refactor: update datepicker interaction, improve destination selection via select2, and add dynamic payment method handling, apos primeiro teste preliminar
This commit is contained in:
@@ -335,19 +335,15 @@ 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
|
# 2. Datepicker — clicar no input #f_dataemissao para abrir calendário
|
||||||
await self._select_date(group.data_venda.day)
|
await self._select_date(group.data_venda.day)
|
||||||
await page.wait_for_timeout(1500)
|
await page.wait_for_timeout(1500)
|
||||||
|
|
||||||
# 3. Origem
|
# 3. Destinatário (origem já implícita no contexto da localidade)
|
||||||
await self._select_origin()
|
|
||||||
await page.wait_for_timeout(1000)
|
|
||||||
|
|
||||||
# 4. Destinatário
|
|
||||||
await self._fill_destination()
|
await self._fill_destination()
|
||||||
await page.wait_for_timeout(1000)
|
await page.wait_for_timeout(1000)
|
||||||
|
|
||||||
# 5. Inserir produtos
|
# 4. Inserir produtos
|
||||||
successful_ids: List[int] = []
|
successful_ids: List[int] = []
|
||||||
failed_products: List[AggregatedProduct] = []
|
failed_products: List[AggregatedProduct] = []
|
||||||
|
|
||||||
@@ -358,7 +354,7 @@ class SigaAutomation:
|
|||||||
else:
|
else:
|
||||||
failed_products.append(product)
|
failed_products.append(product)
|
||||||
|
|
||||||
# 6. Se todos falharam → cancelar
|
# 5. 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()
|
||||||
@@ -368,10 +364,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}")
|
||||||
|
|
||||||
# 7. Ler valor calculado e preencher campo de dinheiro
|
# 6. Ler valor calculado e preencher campo de pagamento
|
||||||
await self._fill_cash_value()
|
await self._fill_payment_value(group.meio_pag)
|
||||||
|
|
||||||
# 8. Confirmar
|
# 7. 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
|
||||||
@@ -379,7 +375,14 @@ 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."""
|
||||||
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)
|
||||||
@@ -397,23 +400,23 @@ class SigaAutomation:
|
|||||||
except PlaywrightTimeout:
|
except PlaywrightTimeout:
|
||||||
logger.warning("⚠️ Datepicker não apareceu, continuando...")
|
logger.warning("⚠️ Datepicker não apareceu, continuando...")
|
||||||
|
|
||||||
async def _select_origin(self):
|
|
||||||
page = self.page
|
|
||||||
await page.get_by_role("cell", name="1", exact=True).first.click()
|
|
||||||
await page.wait_for_timeout(500)
|
|
||||||
await page.get_by_role(
|
|
||||||
"link", name="BR 09-0231 - PRIMAVERA DO LESTE - CENTRO"
|
|
||||||
).click()
|
|
||||||
await page.wait_for_timeout(1000)
|
|
||||||
logger.info("📍 Origem selecionada.")
|
|
||||||
|
|
||||||
async def _fill_destination(self):
|
async def _fill_destination(self):
|
||||||
|
"""Preenche o destinatário via select2 (#s2id_f_pessoa)."""
|
||||||
page = self.page
|
page = self.page
|
||||||
dest = page.get_by_role("combobox", name="Destinatário *")
|
|
||||||
await dest.fill(Config.SIGA_DEST_CODE)
|
# Clicar no select2 para abrir o dropdown
|
||||||
await dest.press("Enter")
|
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)
|
await page.wait_for_timeout(1500)
|
||||||
await page.get_by_text("AVENIDA MINAS GERAIS, 594 -").click()
|
|
||||||
|
# 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)
|
await page.wait_for_timeout(500)
|
||||||
logger.info(f"📍 Destinatário: {Config.SIGA_DEST_CODE}")
|
logger.info(f"📍 Destinatário: {Config.SIGA_DEST_CODE}")
|
||||||
|
|
||||||
@@ -508,24 +511,34 @@ class SigaAutomation:
|
|||||||
await page.wait_for_timeout(2000)
|
await page.wait_for_timeout(2000)
|
||||||
logger.info("🚫 SAÍDA cancelada.")
|
logger.info("🚫 SAÍDA cancelada.")
|
||||||
|
|
||||||
async def _fill_cash_value(self):
|
async def _fill_payment_value(self, meio_pag: str):
|
||||||
|
"""Lê o valor total dos produtos e preenche o campo correto (Dinheiro ou PIX)."""
|
||||||
page = self.page
|
page = self.page
|
||||||
el = page.locator("#f_valoratual")
|
|
||||||
|
|
||||||
# Tenta ler como input primeiro, fallback para inner_text
|
# Ler o valor total dos produtos calculado pelo sistema
|
||||||
try:
|
try:
|
||||||
valor = await el.input_value()
|
valor_produtos = await page.locator("#f_valorproduto").input_value()
|
||||||
except Exception:
|
except Exception:
|
||||||
valor = (await el.inner_text()).strip()
|
valor_produtos = "0,00"
|
||||||
|
|
||||||
if not valor:
|
if not valor_produtos or valor_produtos.strip() == "":
|
||||||
logger.warning("⚠️ #f_valoratual vazio!")
|
valor_produtos = "0,00"
|
||||||
valor = "0"
|
|
||||||
|
|
||||||
cash_field = page.get_by_role("textbox", name="Valor em Dinheiro no Caixa *")
|
if meio_pag == "DINHEIRO":
|
||||||
await cash_field.click()
|
field = page.locator("#f_valorcaixa")
|
||||||
await cash_field.fill(valor)
|
await field.click()
|
||||||
logger.info(f"💰 Valor em Dinheiro no Caixa: {valor}")
|
await field.fill(valor_produtos)
|
||||||
|
logger.info(f"💰 Valor em Dinheiro no Caixa: {valor_produtos}")
|
||||||
|
elif meio_pag == "PIX":
|
||||||
|
field = page.locator("#f_valorQrcodePix")
|
||||||
|
await field.click()
|
||||||
|
await field.fill(valor_produtos)
|
||||||
|
logger.info(f"💰 Pagto QRCode/PIX: {valor_produtos}")
|
||||||
|
else:
|
||||||
|
field = page.locator("#f_valorcaixa")
|
||||||
|
await field.click()
|
||||||
|
await field.fill(valor_produtos)
|
||||||
|
logger.info(f"💰 Valor (fallback dinheiro): {valor_produtos}")
|
||||||
|
|
||||||
async def _confirm(self):
|
async def _confirm(self):
|
||||||
page = self.page
|
page = self.page
|
||||||
|
|||||||
Reference in New Issue
Block a user