Ajustes na abertura do fundo biblico
This commit is contained in:
@@ -285,15 +285,25 @@ class SigaAutomation:
|
|||||||
async def navigate_to_fundo_biblico(self):
|
async def navigate_to_fundo_biblico(self):
|
||||||
page = self.page
|
page = self.page
|
||||||
|
|
||||||
link1 = page.get_by_role("link", name=" PRIMAVERA DO LESTE DL -")
|
try:
|
||||||
if await link1.is_visible(timeout=5000):
|
# 1. Clicar no menu principal de localidade no topo
|
||||||
await link1.click()
|
locality_dropdown = page.locator('//*[@id="navbar-container"]/div[2]/ul/li[3]/a')
|
||||||
await page.wait_for_timeout(1500)
|
if await locality_dropdown.is_visible(timeout=5000):
|
||||||
|
await locality_dropdown.click()
|
||||||
|
await page.wait_for_timeout(1000)
|
||||||
|
|
||||||
link2 = page.get_by_role("link", name="BR 09-0231 - PRIMAVERA DO")
|
# 2. Hover em "Localidades"
|
||||||
if await link2.is_visible(timeout=5000):
|
localidades_menu = page.locator('//*[@id="navbar-container"]/div[2]/ul/li[3]/ul/li[2]/a')
|
||||||
await link2.click()
|
await localidades_menu.hover()
|
||||||
|
await localidades_menu.click()
|
||||||
|
await page.wait_for_timeout(1000)
|
||||||
|
|
||||||
|
# 3. Clicar na localidade alvo (BR 09-0231 - PRIMAVERA DO LESTE - CENTRO)
|
||||||
|
target_locality = page.locator('//*[@id="5044"]/a')
|
||||||
|
await target_locality.click()
|
||||||
await page.wait_for_timeout(1500)
|
await page.wait_for_timeout(1500)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"⚠️ Erro ao tentar mudar localidade: {e}")
|
||||||
|
|
||||||
await page.get_by_role("link", name=" Fundo Bíblico").click()
|
await page.get_by_role("link", name=" Fundo Bíblico").click()
|
||||||
await page.wait_for_timeout(2000)
|
await page.wait_for_timeout(2000)
|
||||||
@@ -335,15 +345,19 @@ class SigaAutomation:
|
|||||||
await page.get_by_role("link", name="Saída").click()
|
await page.get_by_role("link", name="Saída").click()
|
||||||
await page.wait_for_timeout(1500)
|
await page.wait_for_timeout(1500)
|
||||||
|
|
||||||
# 2. Datepicker — clicar no input #f_dataemissao para abrir calendário
|
# 2. Datepicker (aparece automaticamente após clicar "Saída")
|
||||||
await self._select_date(group.data_venda.day)
|
await self._select_date(group.data_venda.day)
|
||||||
await page.wait_for_timeout(1500)
|
|
||||||
|
|
||||||
# 3. Destinatário (origem já implícita no contexto da localidade)
|
# Aguardar loading do sistema (spinner "Aguarde...") após seleção de data
|
||||||
await self._fill_destination()
|
# O destinatário é preenchido automaticamente após a data
|
||||||
|
await page.wait_for_timeout(2000)
|
||||||
|
try:
|
||||||
|
await page.locator("text=Aguarde...").wait_for(state="hidden", timeout=10000)
|
||||||
|
except PlaywrightTimeout:
|
||||||
|
pass
|
||||||
await page.wait_for_timeout(1000)
|
await page.wait_for_timeout(1000)
|
||||||
|
|
||||||
# 4. Inserir produtos
|
# 3. Inserir produtos
|
||||||
successful_ids: List[int] = []
|
successful_ids: List[int] = []
|
||||||
failed_products: List[AggregatedProduct] = []
|
failed_products: List[AggregatedProduct] = []
|
||||||
|
|
||||||
@@ -354,7 +368,7 @@ class SigaAutomation:
|
|||||||
else:
|
else:
|
||||||
failed_products.append(product)
|
failed_products.append(product)
|
||||||
|
|
||||||
# 5. Se todos falharam → cancelar
|
# 4. Se todos falharam → cancelar
|
||||||
if not successful_ids:
|
if not successful_ids:
|
||||||
logger.error("❌ Todos produtos falharam! Cancelando SAÍDA...")
|
logger.error("❌ Todos produtos falharam! Cancelando SAÍDA...")
|
||||||
await self._cancel_saida()
|
await self._cancel_saida()
|
||||||
@@ -364,10 +378,10 @@ class SigaAutomation:
|
|||||||
codes = [p.code for p in failed_products]
|
codes = [p.code for p in failed_products]
|
||||||
logger.warning(f"⚠️ Produtos não encontrados: {codes}")
|
logger.warning(f"⚠️ Produtos não encontrados: {codes}")
|
||||||
|
|
||||||
# 6. Ler valor calculado e preencher campo de pagamento
|
# 5. Ler valor calculado e preencher campo de pagamento
|
||||||
await self._fill_payment_value(group.meio_pag)
|
await self._fill_payment_value(group.meio_pag)
|
||||||
|
|
||||||
# 7. Confirmar
|
# 6. Confirmar
|
||||||
await self._confirm()
|
await self._confirm()
|
||||||
logger.info(f"✅ SAÍDA confirmada! IDs: {successful_ids}")
|
logger.info(f"✅ SAÍDA confirmada! IDs: {successful_ids}")
|
||||||
return successful_ids
|
return successful_ids
|
||||||
@@ -375,14 +389,9 @@ class SigaAutomation:
|
|||||||
# ---------- AÇÕES INTERNAS ----------
|
# ---------- AÇÕES INTERNAS ----------
|
||||||
|
|
||||||
async def _select_date(self, day: int):
|
async def _select_date(self, day: int):
|
||||||
"""Clica no input de data para abrir o datepicker Bootstrap e seleciona o dia."""
|
"""Seleciona o dia no datepicker Bootstrap (aparece automaticamente)."""
|
||||||
page = self.page
|
page = self.page
|
||||||
|
|
||||||
# Clicar no input de data para abrir o calendário
|
|
||||||
date_input = page.locator("#f_dataemissao")
|
|
||||||
await date_input.click()
|
|
||||||
await page.wait_for_timeout(500)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dp = page.locator(".datepicker-days")
|
dp = page.locator(".datepicker-days")
|
||||||
await dp.wait_for(state="visible", timeout=5000)
|
await dp.wait_for(state="visible", timeout=5000)
|
||||||
@@ -400,26 +409,6 @@ class SigaAutomation:
|
|||||||
except PlaywrightTimeout:
|
except PlaywrightTimeout:
|
||||||
logger.warning("⚠️ Datepicker não apareceu, continuando...")
|
logger.warning("⚠️ Datepicker não apareceu, continuando...")
|
||||||
|
|
||||||
async def _fill_destination(self):
|
|
||||||
"""Preenche o destinatário via select2 (#s2id_f_pessoa)."""
|
|
||||||
page = self.page
|
|
||||||
|
|
||||||
# Clicar no select2 para abrir o dropdown
|
|
||||||
await page.locator("#s2id_f_pessoa .select2-choice").click()
|
|
||||||
await page.wait_for_timeout(500)
|
|
||||||
|
|
||||||
# Digitar o código no campo de busca
|
|
||||||
search = page.locator("#select2-drop input.select2-input")
|
|
||||||
await search.fill(Config.SIGA_DEST_CODE)
|
|
||||||
await page.wait_for_timeout(1500)
|
|
||||||
|
|
||||||
# Selecionar o resultado que contém o código
|
|
||||||
result = page.locator("#select2-drop .select2-results li").first
|
|
||||||
await result.wait_for(state="visible", timeout=5000)
|
|
||||||
await result.click()
|
|
||||||
await page.wait_for_timeout(500)
|
|
||||||
logger.info(f"📍 Destinatário: {Config.SIGA_DEST_CODE}")
|
|
||||||
|
|
||||||
async def _add_product(self, code: str, qty: int) -> bool:
|
async def _add_product(self, code: str, qty: int) -> bool:
|
||||||
"""Insere um produto na SAÍDA. Retorna True se OK."""
|
"""Insere um produto na SAÍDA. Retorna True se OK."""
|
||||||
page = self.page
|
page = self.page
|
||||||
@@ -506,7 +495,7 @@ class SigaAutomation:
|
|||||||
|
|
||||||
async def _cancel_saida(self):
|
async def _cancel_saida(self):
|
||||||
page = self.page
|
page = self.page
|
||||||
cancel = page.locator("button.btn.btn-link.no-border", has_text="Cancelar")
|
cancel = page.locator('button.btn.btn-link.no-border[data-dismiss="modal"]', has_text="Cancelar")
|
||||||
await cancel.click()
|
await cancel.click()
|
||||||
await page.wait_for_timeout(2000)
|
await page.wait_for_timeout(2000)
|
||||||
logger.info("🚫 SAÍDA cancelada.")
|
logger.info("🚫 SAÍDA cancelada.")
|
||||||
|
|||||||
Reference in New Issue
Block a user