Skip to content

Commit

Permalink
dacte: add modal dutoviario
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoMafraJunior committed Dec 12, 2024
1 parent bf78415 commit 540662d
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 2 deletions.
139 changes: 137 additions & 2 deletions brazilfiscalreport/dacte/dacte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
190 changes: 190 additions & 0 deletions tests/fixtures/dacte_dutoviario_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CTe xmlns="http://www.portalfiscal.inf.br/cte">
<infCte versao="4.00" Id="CTe35240781583054000129570010000057711040645890">
<ide>
<cUF>35</cUF>
<cCT>57000111</cCT>
<CFOP>5352</CFOP>
<natOp>Venda</natOp>
<mod>57</mod>
<serie>1</serie>
<nCT>577</nCT>
<dhEmi>2020-01-01T12:00:00+01:00</dhEmi>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>0</cDV>
<tpAmb>2</tpAmb>
<tpCTe>0</tpCTe>
<procEmi>0</procEmi>
<verProc>Odoo Brasil OCA v14</verProc>
<cMunEnv>3550308</cMunEnv>
<xMunEnv>São Paulo</xMunEnv>
<UFEnv>SP</UFEnv>
<modal>05</modal>
<tpServ>0</tpServ>
<cMunIni>3550308</cMunIni>
<xMunIni>São Paulo</xMunIni>
<UFIni>SP</UFIni>
<cMunFim>1302603</cMunFim>
<xMunFim>Manaus</xMunFim>
<UFFim>AM</UFFim>
<retira>1</retira>
<indIEToma>1</indIEToma>
<toma3>
<toma>3</toma>
</toma3>
</ide>
<compl>
<xObs>Documento emitido por: Marc Demo</xObs>
<ObsFisco xCampo="Usuário emissor">
<xTexto>Documento emitido por: Marc Demo</xTexto>
</ObsFisco>
</compl>
<emit>
<CNPJ>81583054000129</CNPJ>
<IE>078016350838</IE>
<xNome>Empresa Lucro Presumido Ltda</xNome>
<xFant>Empresa Lucro Presumido</xFant>
<enderEmit>
<xLgr>Avenida Paulista</xLgr>
<nro>1</nro>
<xBairro>Bela Vista</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>01311000</CEP>
<UF>SP</UF>
<fone>551199999999</fone>
</enderEmit>
<CRT>3</CRT>
</emit>
<rem>
<CNPJ>12046835000161</CNPJ>
<IE>887273429152</IE>
<xNome>CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<xFant>Cliente 2 -SP - Simples Nacional</xFant>
<fone>1177777777</fone>
<enderReme>
<xLgr>Avenida Doutor Chucri Zaidan</xLgr>
<nro>950</nro>
<xBairro>Vila Cordeiro</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>04583110</CEP>
<UF>SP</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderReme>
<email>[email protected]</email>
</rem>
<exped>
<CNPJ>12046835000161</CNPJ>
<IE>887273429152</IE>
<xNome>CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<fone>1177777777</fone>
<enderExped>
<xLgr>Avenida Doutor Chucri Zaidan</xLgr>
<nro>950</nro>
<xBairro>Vila Cordeiro</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>04583110</CEP>
<UF>SP</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderExped>
<email>[email protected]</email>
</exped>
<receb>
<CNPJ>84148732000113</CNPJ>
<IE>095693211</IE>
<xNome>CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<fone>9221458888</fone>
<enderReceb>
<xLgr>Avenida Javari</xLgr>
<nro>s/n</nro>
<xCpl>Lote 9.45/15E</xCpl>
<xBairro>Distrito Industrial</xBairro>
<cMun>1302603</cMun>
<xMun>Manaus</xMun>
<CEP>69075110</CEP>
<UF>AM</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderReceb>
<email>[email protected]</email>
</receb>
<dest>
<CNPJ>46081676000158</CNPJ>
<IE>782175040</IE>
<xNome>CTE EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<fone>9221459999</fone>
<ISUF>101362102</ISUF>
<enderDest>
<xLgr>Avenida Javari</xLgr>
<nro>s/n</nro>
<xCpl>Lote 8.45/30E</xCpl>
<xBairro>Distrito Industrial</xBairro>
<cMun>1302603</cMun>
<xMun>Manaus</xMun>
<CEP>69075110</CEP>
<UF>AM</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderDest>
<email>[email protected]</email>
</dest>
<vPrest>
<vTPrest>47.00</vTPrest>
<vRec>47.00</vRec>
<Comp>
<xNome>Frete</xNome>
<vComp>47.00</vComp>
</Comp>
</vPrest>
<imp>
<ICMS>
<ICMS00>
<CST>00</CST>
<vBC>47.00</vBC>
<pICMS>18.00</pICMS>
<vICMS>8.46</vICMS>
</ICMS00>
</ICMS>
</imp>
<infCTeNorm>
<infCarga>
<vCarga>1000.00</vCarga>
<proPred>XYZ Product</proPred>
<xOutCat>Other Product Data</xOutCat>
<infQ>
<cUnid>00</cUnid>
<tpMed>Volume</tpMed>
<qCarga>1000.0000</qCarga>
</infQ>
<infQ>
<cUnid>01</cUnid>
<tpMed>Peso Bruto</tpMed>
<qCarga>500.0000</qCarga>
</infQ>
<infQ>
<cUnid>03</cUnid>
<tpMed>Unidade</tpMed>
<qCarga>2.0000</qCarga>
</infQ>
<vCargaAverb>1000.00</vCargaAverb>
</infCarga>
<infDoc>
<infNFe>
<chave>41190806117473000150550010000586251016759484</chave>
</infNFe>
</infDoc>
<infModal versaoModal="4.00">
<duto>
<vTar>1500.000000</vTar>
<dIni>2024-01-01</dIni>
<dFim>2024-12-31</dFim>
</duto>
</infModal>
</infCTeNorm>
</infCte>
</CTe>
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test_dacte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 540662d

Please sign in to comment.