Skip to content

Commit

Permalink
add romaneio_inicio, change names and fix bug with int(number_with_co…
Browse files Browse the repository at this point in the history
…mma)
  • Loading branch information
ntaraujo committed Feb 21, 2022
1 parent f5fb11f commit 773b3bc
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/actions/romaneio.py → src/actions/romaneio_completo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import re


class Romaneio(WebToExcelAction):
class RomaneioCompleto(WebToExcelAction):
def __init__(self, args, web, excel):
super().__init__(args, web, excel)

Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self, args, web, excel):
tam = line[tam_ind].strip()
qtd = line[qtd_ind].strip()
preco = nf_itens_dict[cod_ref][preco_ind].strip()
total = float(preco.replace('.', '').replace(',', '.')) * int(qtd)
total = float(preco.replace('.', '').replace(',', '.')) * int(qtd.replace(',', ''))
total = f'{total:_.2f}'.replace('.', ',').replace('_', '.')

table.append((cod, material, desc, cor, tam, qtd, preco, total, oc))
Expand All @@ -86,7 +86,7 @@ def __init__(self, args, web, excel):
from automators import web, excel
from utils import ExampleArgs

Romaneio(
RomaneioCompleto(
ExampleArgs(),
web.Web(),
excel.Excel()
Expand Down
84 changes: 84 additions & 0 deletions src/actions/romaneio_inicio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# debug helper for vscode
# import os; os.chdir('/Users/macbookpro/Desktop/dev/trendy/src')

if __name__ == '__main__':
from gooey import local_resource_path
from sys import path as sys_path

sys_path.insert(0, local_resource_path(""))

from actions.base_action import WebToExcelAction
from utils import run_scheduled, common_start, global_path
import re


class RomaneioInicio(WebToExcelAction):
def __init__(self, args, web, excel):
super().__init__(args, web, excel)

cac = list(self.excel.get_csv_reader(self.args.cac, reader_kwargs={"delimiter": ";"}))

cnpj = cac[2][0][1:]
nf = cac[5][0]
serie = cac[6][0]
estabelecimento = "20" if nf[0] == "5" else "21"

cod_ind = 1
tam_ind = 5
cor_ind = 4
qtd_ind = 6
cac_start_at = 9

if not self.web.opened:
self.web.open()
self.web.totvs_access()
if not self.web.totvs_logged:
password = self.args.senha_totvs
self.web.totvs_login(password)
self.web.totvs_fav_program_access(3, 16)
self.web.totvs_fav_notas_va_para(estabelecimento, serie, nf)
self.web.totvs_fav_notas_items(nf)
nf_itens = self.web.totvs_fav_notas_complete_table()
desc_ind = 2
preco_ind = 5
nf_itens_start_at = 2
nf_itens_end_at = -1

nf_itens_dict = {line[1].strip()[:10]: line for line in nf_itens[nf_itens_start_at:nf_itens_end_at]}
descs = [re.match(r'(.*) *[A-Z]+ *$', line[desc_ind])[1] for line in nf_itens[nf_itens_start_at:nf_itens_end_at]]
desc = common_start(*descs).strip()

table = []
for line in cac[cac_start_at:]:
cod = line[cod_ind].strip()
cod_ref = cod[:10]

cor = line[cor_ind].strip()
tam = line[tam_ind].strip()
qtd = line[qtd_ind].strip()
preco = nf_itens_dict[cod_ref][preco_ind].strip()
total = float(preco.replace('.', '').replace(',', '.')) * int(qtd.replace(',', ''))
total = f'{total:_.2f}'.replace('.', ',').replace('_', '.')

table.append((cod, None, desc, cor, tam, qtd, preco))

self.excel.open_app()
self.excel.open(global_path("resources/romaneio.xls"))

self.excel.assign('D9', cnpj)
self.excel.assign('G8', [[nf], [serie]])
self.excel.assign('C14', table)

run_scheduled()
self.web.close()


if __name__ == '__main__':
from automators import web, excel
from utils import ExampleArgs

RomaneioInicio(
ExampleArgs(),
web.Web(),
excel.Excel()
)
18 changes: 14 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ def group(parser_, name, **kwargs):
help="Os respectivos nomes para cada cliente, separados por ENTER")


romaneio_parser = sub_parser('Romaneio')
romaneio_parser = sub_parser('RomaneioInício')

romaneio_basic_group = group(romaneio_parser, 'Básico', gooey_options={'columns': 1})
argument(romaneio_basic_group, 'cac', widget='FileChooser', help='Arquivo CAC no formato .csv')
argument(romaneio_basic_group, 'senha_totvs', widget='PasswordField', help="A senha de acesso ao TOTVS")


romaneio_parser = sub_parser('RomaneioCompleto')

romaneio_basic_group = group(romaneio_parser, 'Básico', gooey_options={'columns': 1})
argument(romaneio_basic_group, 'oc', help="Número da ordem de compra")
Expand Down Expand Up @@ -125,9 +132,12 @@ def run(action):
elif args.action == 'Títulos':
from actions.titulos import Titulos
run(Titulos)
elif args.action == 'Romaneio':
from actions.romaneio import Romaneio
run(Romaneio)
elif args.action == 'RomaneioInício':
from actions.romaneio_inicio import RomaneioInicio
run(RomaneioInicio)
elif args.action == 'RomaneioCompleto':
from actions.romaneio_completo import RomaneioCompleto
run(RomaneioCompleto)


if __name__ == '__main__':
Expand Down

0 comments on commit 773b3bc

Please sign in to comment.