diff --git a/brazilfiscalreport/dacte/dacte.py b/brazilfiscalreport/dacte/dacte.py index 925ec34..e3d85c4 100644 --- a/brazilfiscalreport/dacte/dacte.py +++ b/brazilfiscalreport/dacte/dacte.py @@ -280,7 +280,7 @@ def _draw_header(self): section_start_y = y_margin + 4 w_rect = (self.epw / 2) - 33 h_rect = 27 - emit_name = extract_text(self.emit, "xNome") + self.emit_name = extract_text(self.emit, "xNome") self.cep = format_cep(extract_text(self.emit, "CEP")) self.fone = format_phone(extract_text(self.emit, "fone")) self.modal = TP_MODAL[extract_text(self.ide, "modal")] @@ -322,7 +322,7 @@ def _draw_header(self): w_text = w_rect - 4 self.set_font(self.default_font, "B", 9) self.set_xy(x=x_text, y=y_text) - self.multi_cell(w=w_text, h=5, text=emit_name, border=0, align="C") + self.multi_cell(w=w_text, h=5, text=self.emit_name, border=0, align="C") self.set_font(self.default_font, "", 8) self.set_xy(x=x_text - 3, y=y_text + 10) self.multi_cell(w=w_text + 10, h=3, text=address, border=0, align="C") @@ -2060,6 +2060,139 @@ def draw_multimodal_info(self, config): style="", ) + def draw_dutoviario_info(self, config): + x_margin = self.l_margin + page_width = self.epw + + section_start_y = self.get_y() + 7 + section_start_y = self.draw_section( + section_start_y, + 13, + "DADOS ESPECÍFICOS DO MODAL DUTOVIÁRIO", + ) + self.rect( + x=x_margin, + y=section_start_y - 10, + w=page_width - 0.1 * x_margin, + h=6, + style="", + ) + + col_width = (page_width - 2 * x_margin) / 5 + for i in range(1, 5): + x_line = x_margin + i * col_width + self.line( + x1=x_line, + x2=x_line, + y1=section_start_y - 10, + y2=section_start_y - 4, + ) + + self.set_font(self.default_font, "", 6) + road_titles = [ + "VALOR UNITÁRIO", + "VALOR DO FRETE", + "OUTROS", + "BASE DE CÁLCULO", + "ALÍQUOTA", + ] + + road_values = [ + "", + "", + "", + f"{self.vbc}", + f"{self.p_icms}", + ] + + for i, (title, value) in enumerate(zip(road_titles, road_values)): + self.set_xy(x_margin + i * col_width, section_start_y - 10) + self.multi_cell(w=col_width, h=3, text=title, align="L") + self.set_font(self.default_font, "B", 7) + self.set_xy(x_margin + i * col_width, section_start_y - 7) + self.multi_cell(w=col_width, h=3, text=value, align="L") + self.set_font(self.default_font, "", 6) + + section_start_y = self.get_y() + 10 + self.rect( + x=x_margin, + y=section_start_y - 10, + w=page_width - 0.1 * x_margin, + h=6, + style="", + ) + + col_width = (page_width - 2 * x_margin) / 6 + for i in range(1, 6): + x_line = x_margin + i * col_width + self.line( + x1=x_line, + x2=x_line, + y1=section_start_y - 10, + y2=section_start_y - 4, + ) + + self.set_font(self.default_font, "", 6) + road_titles = [ + "VALOR DO IMPOSTO", + "VALOR TOTAL DO FRETE", + "OBSERVAÇÕES", + "SÉRIE", + "NÚMERO", + "EMITENTE", + ] + + road_values = [ + "", + f"R$ {self.v_tpprest}", + "", + f"{self.serie_cte}", + f"{self.nr_dacte}", + f"{self.emit_name}", + ] + + for i, (title, value) in enumerate(zip(road_titles, road_values)): + self.set_xy(x_margin + i * col_width, section_start_y - 10) + self.multi_cell(w=col_width, h=3, text=title, align="L") + if i == 5: + self.set_font(self.default_font, "B", 6) + else: + self.set_font(self.default_font, "B", 7) + self.set_xy(x_margin + i * col_width, section_start_y - 7) + self.multi_cell(w=col_width, h=3, text=value, align="L") + self.set_font(self.default_font, "", 6) + + self.set_font(self.default_font, "", 7) + section_start_y = self.get_y() + section_start_y = self.draw_section( + section_start_y, 3, "USO EXCLUSIVO DO EMISSOR DO CT-E" + ) + self.set_margins( + left=config.margins.left, + top=config.margins.top, + right=config.margins.right, + ) + margins_to_height = { + 2: 20, + 3: 19, + 4: 17, + 5: 16, + 6: 13, + 7: 11, + 8: 11, + 9: 9, + 10: 8, + } + rect_height = margins_to_height[config.margins.left] + + self.rect( + x=x_margin, + y=section_start_y, + w=page_width - 0.1 * x_margin, + h=rect_height, + style="", + ) + def _draw_specific_data(self, config): x_margin = self.l_margin page_width = self.epw @@ -2145,6 +2278,8 @@ def _draw_specific_data(self, config): self.draw_aquaviario_info(config) if self.tp_modal == ModalType.FERROVIARIO: self.draw_ferroviario_info(config) + if self.tp_modal == ModalType.DUTOVIARIO: + self.draw_dutoviario_info(config) if self.tp_modal == ModalType.MULTIMODAL: self.draw_multimodal_info(config) diff --git a/tests/fixtures/dacte_dutoviario_test.xml b/tests/fixtures/dacte_dutoviario_test.xml new file mode 100644 index 0000000..dd1f1f1 --- /dev/null +++ b/tests/fixtures/dacte_dutoviario_test.xml @@ -0,0 +1,190 @@ + + + + + 35 + 57000111 + 5352 + Venda + 57 + 1 + 577 + 2020-01-01T12:00:00+01:00 + 1 + 1 + 0 + 2 + 0 + 0 + Odoo Brasil OCA v14 + 3550308 + São Paulo + SP + 05 + 0 + 3550308 + São Paulo + SP + 1302603 + Manaus + AM + 1 + 1 + + 3 + + + + Documento emitido por: Marc Demo + + Documento emitido por: Marc Demo + + + + 81583054000129 + 078016350838 + Empresa Lucro Presumido Ltda + Empresa Lucro Presumido + + Avenida Paulista + 1 + Bela Vista + 3550308 + São Paulo + 01311000 + SP + 551199999999 + + 3 + + + 12046835000161 + 887273429152 + CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL + Cliente 2 -SP - Simples Nacional + 1177777777 + + Avenida Doutor Chucri Zaidan + 950 + Vila Cordeiro + 3550308 + São Paulo + 04583110 + SP + 1058 + Brasil + + cliente2@cliente2.com.br + + + 12046835000161 + 887273429152 + CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL + 1177777777 + + Avenida Doutor Chucri Zaidan + 950 + Vila Cordeiro + 3550308 + São Paulo + 04583110 + SP + 1058 + Brasil + + cliente2@cliente2.com.br + + + 84148732000113 + 095693211 + CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL + 9221458888 + + Avenida Javari + s/n + Lote 9.45/15E + Distrito Industrial + 1302603 + Manaus + 69075110 + AM + 1058 + Brasil + + cliente4@cliente4.com.br + + + 46081676000158 + 782175040 + CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL + 9221459999 + 101362102 + + Avenida Javari + s/n + Lote 8.45/30E + Distrito Industrial + 1302603 + Manaus + 69075110 + AM + 1058 + Brasil + + cliente3@cliente3.com.br + + + 47.00 + 47.00 + + Frete + 47.00 + + + + + + 00 + 47.00 + 18.00 + 8.46 + + + + + + 1000.00 + XYZ Product + Other Product Data + + 00 + Volume + 1000.0000 + + + 01 + Peso Bruto + 500.0000 + + + 03 + Unidade + 2.0000 + + 1000.00 + + + + 41190806117473000150550010000586251016759484 + + + + + 1500.000000 + 2024-01-01 + 2024-12-31 + + + + + diff --git a/tests/generated/dacte/dacte_default_dutoviario.pdf b/tests/generated/dacte/dacte_default_dutoviario.pdf new file mode 100644 index 0000000..68f8833 Binary files /dev/null and b/tests/generated/dacte/dacte_default_dutoviario.pdf differ diff --git a/tests/test_dacte.py b/tests/test_dacte.py index 0d01af4..dbae5ba 100644 --- a/tests/test_dacte.py +++ b/tests/test_dacte.py @@ -83,6 +83,15 @@ def test_dacte_default_ferroviario(tmp_path, load_dacte, logo_path): assert_pdf_equal(dacte, pdf_path, tmp_path) +def test_dacte_default_dutoviario(tmp_path, load_dacte, logo_path): + dacte_config = DacteConfig( + logo=logo_path, + ) + dacte = load_dacte("dacte_dutoviario_test.xml", config=dacte_config) + pdf_path = get_pdf_output_path("dacte", "dacte_default_dutoviario") + assert_pdf_equal(dacte, pdf_path, tmp_path) + + def test_dacte_default_multimodal(tmp_path, load_dacte, logo_path): dacte_config = DacteConfig( logo=logo_path,