Skip to content

Commit e983656

Browse files
Merge pull request #134 from Escodoo/dacte-ibs-cbs
dacte: display ibs e cbs
2 parents 1a570c5 + a94ecb0 commit e983656

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+66
-4
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
"forwardPorts": [
3131
8501
3232
]
33-
}
33+
}

brazilfiscalreport/dacte/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ class DacteConfig:
4747
decimal_config: DecimalConfig = field(default_factory=DecimalConfig)
4848
font_type: FontType = FontType.TIMES
4949
watermark_cancelled: bool = False
50+
display_ibs_cbs: bool = False

brazilfiscalreport/dacte/dacte.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, xml, config: DacteConfig = None):
5858
self.price_precision = config.decimal_config.price_precision
5959
self.quantity_precision = config.decimal_config.quantity_precision
6060
self.watermark_cancelled = config.watermark_cancelled
61+
self.display_ibs_cbs = config.display_ibs_cbs
6162

6263
root = ET.fromstring(xml)
6364
self.inf_cte = root.find(f"{URL}infCte")
@@ -80,6 +81,7 @@ def __init__(self, xml, config: DacteConfig = None):
8081
self.compl = root.find(f"{URL}compl") or []
8182
self.aquav = root.find(f"{URL}aquav")
8283
self.ferrov = root.find(f"{URL}ferrov")
84+
self.imp_ibscbs = root.find(f"{URL}IBSCBS")
8385

8486
self.obs_dacte_list = []
8587
for obs in self.compl:
@@ -1286,6 +1288,24 @@ def _draw_service_fee_value(self):
12861288
self.v_icms = format_number(extract_text(self.imp, "vICMS"), precision=2)
12871289
self.v_icms_st = format_number(extract_text(self.imp, "vICMS"), precision=2)
12881290
self.p_red_bc = format_number(extract_text(self.imp, "pRedBC"), precision=2)
1291+
g_ibscbs = (
1292+
self.imp_ibscbs.find(f"{URL}gIBSCBS")
1293+
if self.imp_ibscbs is not None
1294+
else None
1295+
)
1296+
g_uf = g_ibscbs.find(f"{URL}gIBSUF") if g_ibscbs is not None else None
1297+
g_mun = g_ibscbs.find(f"{URL}gIBSMun") if g_ibscbs is not None else None
1298+
g_cbs = g_ibscbs.find(f"{URL}gCBS") if g_ibscbs is not None else None
1299+
self.p_ibs_uf = format_number(extract_text(g_uf, "pIBSUF") or "0", precision=2)
1300+
self.v_ibs_uf = format_number(extract_text(g_uf, "vIBSUF") or "0", precision=2)
1301+
self.p_ibs_mun = format_number(
1302+
extract_text(g_mun, "pIBSMun") or "0", precision=2
1303+
)
1304+
self.v_ibs_mun = format_number(
1305+
extract_text(g_mun, "vIBSMun") or "0", precision=2
1306+
)
1307+
self.p_cbs = format_number(extract_text(g_cbs, "pCBS") or "0", precision=2)
1308+
self.v_cbs = format_number(extract_text(g_cbs, "vCBS") or "0", precision=2)
12891309
self.rntrc = extract_text(self.inf_modal, "RNTRC")
12901310
self.x_obs = extract_text(self.compl, "compl")
12911311
self.v_tpprest = format_number(
@@ -1373,15 +1393,22 @@ def print_column(components, x_start):
13731393
section_start_y, 18, "INFORMAÇÕES RELATIVAS AO IMPOSTO"
13741394
)
13751395
self.cst_desc = TP_ICMS[extract_text(self.imp, "CST")]
1396+
total_width = page_width - 0.1 * x_margin
13761397
self.rect(
13771398
x=x_margin,
13781399
y=section_start_y - 15,
1379-
w=page_width - 0.1 * x_margin,
1400+
w=total_width,
13801401
h=15,
13811402
style="",
13821403
)
13831404

1384-
col_width = (page_width - 2 * x_margin) / 6
1405+
if self.display_ibs_cbs:
1406+
ibs_width = total_width * 0.15
1407+
col_width = (total_width - ibs_width) / 6
1408+
else:
1409+
col_width = total_width / 6
1410+
ibs_width = 0
1411+
13851412
for i in range(1, 6):
13861413
x_line = x_margin + i * col_width
13871414
self.line(x1=x_line, x2=x_line, y1=section_start_y - 15, y2=section_start_y)
@@ -1411,6 +1438,38 @@ def print_column(components, x_start):
14111438
self.multi_cell(w=col_width, h=4, text=value, align="L")
14121439
self.set_font(self.default_font, "", 6)
14131440

1441+
if self.display_ibs_cbs:
1442+
col_ibs = x_margin + 6 * col_width
1443+
self.set_font(self.default_font, "", 6)
1444+
self.line(
1445+
x1=col_ibs,
1446+
x2=col_ibs,
1447+
y1=section_start_y - 15,
1448+
y2=section_start_y,
1449+
)
1450+
self.set_xy(col_ibs, section_start_y - 15)
1451+
self.multi_cell(w=ibs_width, h=4, text="IBS E CBS", align="L")
1452+
self.set_font(self.default_font, "B", 4.8)
1453+
valor_area_h = 11
1454+
line_h = valor_area_h / 3
1455+
y_start = section_start_y - 15 + 4
1456+
w_label = ibs_width * 0.58
1457+
w_val = ibs_width * 0.21
1458+
ibs_rows = [
1459+
("IBS ESTADUAL (%/R$)", self.p_ibs_uf, self.v_ibs_uf),
1460+
("IBS MUNICIPAL (%/R$)", self.p_ibs_mun, self.v_ibs_mun),
1461+
("CBS (%/R$)", self.p_cbs, self.v_cbs),
1462+
]
1463+
for i, (label, pct, val) in enumerate(ibs_rows):
1464+
y_row = y_start + i * line_h
1465+
self.set_xy(col_ibs, y_row)
1466+
self.cell(w=w_label, h=line_h, text=label, align="L")
1467+
self.set_xy(col_ibs + w_label + 0.8, y_row)
1468+
self.cell(w=w_val, h=line_h, text=pct, align="R")
1469+
self.set_xy(col_ibs + w_label + w_val + 1, y_row)
1470+
self.cell(w=w_val, h=line_h, text=val, align="R")
1471+
self.set_xy(col_ibs + w_label + w_val + 0.8, y_row - 3.2)
1472+
14141473
def _draw_documents_obs(self):
14151474
x_margin = self.l_margin
14161475
page_width = self.epw

tests/generated/dacce/cce.pdf

6 Bytes
Binary file not shown.
5 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.
11 Bytes
Binary file not shown.
20 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.
5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)