Skip to content

Commit e8f79d5

Browse files
committed
[IMP] l10n_br_fiscal: operation/line docstring
1 parent 516177d commit e8f79d5

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

l10n_br_fiscal/models/operation.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,54 @@
1717

1818

1919
class Operation(models.Model):
20+
"""
21+
Defines a Fiscal Operation, representing the nature and fiscal intent of
22+
a transaction (e.g., Sale, Return, Import, Industrialization).
23+
24+
A Fiscal Operation is a core configuration entity in the Brazilian
25+
fiscal localization. It serves as a central point to orchestrate how
26+
fiscal documents and their lines are processed by determining:
27+
28+
1. **Transaction Type**: Specifies if the operation is an Inbound
29+
(e.g., purchase, return from customer), Outbound (e.g., sale,
30+
return to supplier), or Other type of fiscal movement.
31+
32+
2. **Operation Lines (`line_ids`)**: Each Fiscal Operation contains
33+
one or more `l10n_br_fiscal.operation.line` records. These lines
34+
define specific rules or conditions (based on partner profiles,
35+
product types, company tax regime, etc.) under which a
36+
particular set of fiscal treatments apply. The system selects
37+
the "best match" operation line based on the context of a
38+
transaction.
39+
40+
3. **CFOP (Código Fiscal de Operações e Prestações)**: The selected
41+
`operation.line` determines the appropriate CFOP codes
42+
(internal, external, export) for the transaction line. The CFOP
43+
itself carries significant fiscal meaning and influences tax
44+
calculations and reporting.
45+
46+
4. **Tax Definitions (`tax_definition_ids` on `operation.line` and `cfop`)**:
47+
The selected `operation.line` and the determined `cfop` can both
48+
hold `l10n_br_fiscal.tax.definition` records. These tax
49+
definitions specify which taxes (ICMS, IPI, PIS, COFINS, etc.)
50+
apply, along with their respective CST/CSOSN codes and other
51+
parameters. This linkage allows the Fiscal Operation to drive
52+
the tax calculation engine.
53+
54+
5. **Document Characteristics**: It can also define default behaviors
55+
or properties for documents generated under this operation, such
56+
as the electronic document purpose (`edoc_purpose`), default
57+
price type (sale vs. cost), and links to inverse or return
58+
operations.
59+
60+
Essentially, when a fiscal document is created, the user selects a
61+
Fiscal Operation. The system then uses this operation and the
62+
transactional context (partner, product, company) to find the most
63+
suitable `operation.line`. This line, in turn, provides the CFOP
64+
and a set of tax definitions, which are then used by the tax engine
65+
to calculate all applicable taxes.
66+
"""
67+
2068
_name = "l10n_br_fiscal.operation"
2169
_description = "Fiscal Operation"
2270
_inherit = ["mail.thread", "mail.activity.mixin"]

l10n_br_fiscal/models/operation_line.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,52 @@ def map_fiscal_taxes(
201201
service_type=None,
202202
ind_final=None,
203203
):
204+
"""
205+
Map and determine the applicable fiscal taxes, CFOP, IPI guideline,
206+
and ICMS tax benefit for a given context.
207+
208+
The method aggregates tax definitions from various sources, applying a
209+
precedence order:
210+
1. Company-level tax definitions.
211+
2. NCM-defined taxes (IPI, II).
212+
3. ICMS Regulation specific taxes.
213+
4. Taxes defined directly on this fiscal operation line.
214+
5. Taxes defined on the determined CFOP.
215+
6. Taxes from the partner's fiscal profile.
216+
217+
It also filters taxes based on whether the product is subject to
218+
ICMS or ISSQN.
219+
220+
:param company: The company record (res.company).
221+
:param partner: The partner record (res.partner).
222+
:param product: Optional product record (product.product).
223+
:param fiscal_price: (Unused in direct logic; kept for signature
224+
consistency for overrides/extensions)
225+
:param fiscal_quantity: (Unused in direct logic; kept for signature
226+
consistency for overrides/extensions)
227+
:param ncm: Optional NCM record (l10n_br_fiscal.ncm);
228+
defaults to product's NCM.
229+
:param nbm: Optional NBM record (l10n_br_fiscal.nbm);
230+
defaults to product's NBM.
231+
:param nbs: Optional NBS record (l10n_br_fiscal.nbs);
232+
defaults to product's NBS.
233+
:param cest: Optional CEST record (l10n_br_fiscal.cest);
234+
defaults to product's CEST.
235+
:param city_taxation_code: Optional City Taxation Code record
236+
(l10n_br_fiscal.city.taxation.code).
237+
:param service_type: Optional Service Type record
238+
(l10n_br_fiscal.service.type).
239+
:param ind_final: (Passed to icms_regulation_id.map_tax; not directly
240+
used for tax calculation here)
241+
:return: A dictionary containing:
242+
- 'taxes': A dictionary of applicable tax records
243+
(l10n_br_fiscal.tax) keyed by their tax_domain.
244+
- 'cfop': The determined CFOP record (l10n_br_fiscal.cfop).
245+
- 'ipi_guideline': The determined IPI guideline record
246+
(l10n_br_fiscal.tax.ipi.guideline).
247+
- 'icms_tax_benefit_id': The determined ICMS tax benefit record
248+
ID (l10n_br_fiscal.tax.definition) or False.
249+
"""
204250
mapping_result = {
205251
"taxes": {},
206252
"cfop": False,

0 commit comments

Comments
 (0)