Skip to content

Commit 748fa4e

Browse files
committed
[IMP] l10n_br_fiscal: doc/line/mixin docstring
1 parent 2de0864 commit 748fa4e

File tree

6 files changed

+165
-22
lines changed

6 files changed

+165
-22
lines changed

l10n_br_fiscal/models/document.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,30 @@
3131

3232

3333
class Document(models.Model):
34-
"""Implementação base dos documentos fiscais
35-
36-
Devemos sempre ter em mente que o modelo que vai usar este módulo abstrato
37-
tem diversos metodos importantes e a intenção que os módulos da OCA que
38-
extendem este modelo, funcionem se possível sem a necessidade de
39-
codificação extra.
40-
41-
É preciso também estar atento que o documento fiscal tem dois estados:
42-
43-
- Estado do documento eletrônico / não eletônico: state_edoc
44-
- Estado FISCAL: state_fiscal
45-
46-
O estado fiscal é um campo que é alterado apenas algumas vezes pelo código
47-
e é de responsabilidade do responsável fiscal pela empresa de manter a
48-
integridade do mesmo, pois ele não tem um fluxo realmente definido e
49-
interfere no lançamento do registro no arquivo do SPED FISCAL.
34+
"""
35+
Base implementation for Brazilian fiscal documents.
36+
37+
This model serves as the foundational structure for various fiscal
38+
documents within the Brazilian localization. It's designed to be
39+
extensible, allowing other OCA modules to build upon it, ideally
40+
minimizing the need for additional custom coding for common fiscal
41+
document functionalities.
42+
43+
Key aspects to note:
44+
- The fiscal document manages two primary states:
45+
- Electronic Document State (`state_edoc`): Reflects the status
46+
of the document in its electronic lifecycle (e.g., Draft,
47+
Authorized, Cancelled).
48+
- Fiscal State (`state_fiscal`): Represents the document's status
49+
from a purely fiscal accounting perspective (e.g., Regular,
50+
Cancelled for fiscal purposes). This state is less automated
51+
and often managed by the fiscal responsible to ensure correct
52+
reporting, such as in SPED Fiscal.
53+
54+
This model inherits common fields and methods from
55+
`l10n_br_fiscal.document.mixin` and includes features for document
56+
numbering, key validation, partner and company fiscal details, line
57+
items, and workflows for subsequent document generation and returns.
5058
"""
5159

5260
_name = "l10n_br_fiscal.document"

l10n_br_fiscal/models/document_line.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66

77
class DocumentLine(models.Model):
8+
"""
9+
Represents a line item within a Brazilian fiscal document.
10+
11+
This model defines the core structure of a fiscal document line,
12+
primarily linking it to its parent document (`l10n_br_fiscal.document`)
13+
and holding essential line-specific data like quantity and a
14+
descriptive name.
15+
16+
The vast majority of detailed fiscal fields (e.g., product, NCM,
17+
CFOP, various tax bases and values) and their complex computation
18+
logic are inherited from `l10n_br_fiscal.document.line.mixin`.
19+
This delegation ensures code reusability and keeps this model
20+
focused on its direct relationships and core line properties.
21+
"""
22+
823
_name = "l10n_br_fiscal.document.line"
924
_inherit = "l10n_br_fiscal.document.line.mixin"
1025
_description = "Fiscal Document Line"

l10n_br_fiscal/models/document_line_mixin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@
4949

5050

5151
class FiscalDocumentLineMixin(models.AbstractModel):
52+
"""
53+
Provides the primary field structure for Brazilian fiscal document lines.
54+
55+
It is inherited by sale.order.line, purchase.order.linne, account.move.line
56+
and even stock.move in separate modules.
57+
Indeed these business documents need to take care of some fiscal parameters
58+
before creating Fiscal Document Lines. And of course,
59+
Fiscal Document Lines themselves inherit from this mixin.
60+
61+
This abstract model defines an extensive set of fields necessary for
62+
line-item fiscal calculations and reporting in Brazil. It includes:
63+
- Product and quantity information.
64+
- Detailed fiscal classifications (NCM, CFOP, CEST, etc.).
65+
- Fields for each specific Brazilian tax (ICMS, IPI, PIS, COFINS,
66+
ISSQN, etc.), covering their respective bases, rates, and
67+
calculated values.
68+
- Line-level totals and cost components.
69+
70+
It inherits computational logic, onchange handlers, and other complex
71+
methods from `l10n_br_fiscal.document.line.mixin.methods`. Models
72+
that represent actual document lines (e.g.,
73+
`l10n_br_fiscal.document.line`) should inherit this mixin to
74+
acquire the necessary fiscal field definitions and associated behaviors.
75+
"""
76+
5277
_name = "l10n_br_fiscal.document.line.mixin"
5378
_inherit = "l10n_br_fiscal.document.line.mixin.methods"
5479
_description = "Document Fiscal Mixin"

l10n_br_fiscal/models/document_line_mixin_methods.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@
4646

4747

4848
class FiscalDocumentLineMixinMethods(models.AbstractModel):
49+
"""
50+
Provides the method implementations for l10n_br_fiscal.document.line.mixin.
51+
52+
These methods are extracted into this separate mixin due to the way
53+
l10n_br_fiscal.document.line is incorporated into account.move.line
54+
by the l10n_br_account module (decorator pattern).
55+
56+
Specifically:
57+
- In l10n_br_account, fields from l10n_br_fiscal.document.line
58+
are added to account.move.line using Odoo's `_inherits` (composition)
59+
mechanism.
60+
- The methods in *this* mixin, however, are intended to be inherited
61+
using the standard `_inherit` mechanism.
62+
63+
This separation is crucial because `_inherits` handles field composition
64+
but does not inherit methods. Thus, `_inherit` is used to bring in
65+
these methods. If these methods were defined in the same class as the
66+
fields of l10n_br_fiscal.document.line.mixin (which are subject to
67+
`_inherits`), and account.move.line also used `_inherit` on that
68+
single class, the fields would be duplicated.
69+
"""
70+
4971
_name = "l10n_br_fiscal.document.line.mixin.methods"
5072
_description = "Fiscal Document Mixin Methods"
5173

l10n_br_fiscal/models/document_mixin.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@
1616

1717

1818
class FiscalDocumentMixin(models.AbstractModel):
19+
"""
20+
Provides a collection of reusable methods for Brazilian fiscal document logic.
21+
22+
This abstract model is intended to be inherited by other models or mixins
23+
that require fiscal document functionalities, such as preparing fiscal data,
24+
calculating fiscal amounts, managing document series, and handling comments.
25+
26+
It is inherited by sale.order, purchase.order, account.move and even stock.picking
27+
in separate modules. Indeed these business documents need to take care of
28+
some fiscal parameters before creating Fiscal Documents. And of course,
29+
Fiscal Document themselves inherit from this mixin.
30+
31+
Key functionalities include:
32+
- Computation of various fiscal amounts based on document lines.
33+
- Inverse methods for distributing header-level costs (freight, insurance)
34+
to lines.
35+
- Hooks for customizing data retrieval (e.g., lines, fiscal partner).
36+
- Onchange helpers for common fiscal fields.
37+
38+
Models using this mixin are often expected to also include fields defined
39+
in `l10n_br_fiscal.document.mixin` for methods like
40+
`_prepare_br_fiscal_dict` and `_get_amount_fields` to function
41+
correctly. Line-based calculations typically rely on an overrideable
42+
`_get_amount_lines` method.
43+
"""
44+
1945
_name = "l10n_br_fiscal.document.mixin"
2046
_inherit = "l10n_br_fiscal.document.mixin.methods"
2147
_description = "Document Fiscal Mixin Fields"

l10n_br_fiscal/models/document_mixin_methods.py

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) 2019 Renato Lima - Akretion <renato.lima@akretion.com.br>
22
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33

4-
from odoo import api, models
4+
from odoo import Command, api, models
55

66
from ..constants.fiscal import (
77
COMMENT_TYPE_COMMERCIAL,
@@ -11,6 +11,28 @@
1111

1212

1313
class FiscalDocumentMixinMethods(models.AbstractModel):
14+
"""
15+
Provides the method implementations for l10n_br_fiscal.document.mixin.
16+
17+
These methods are extracted into this separate mixin due to the way
18+
l10n_br_fiscal.document.line is incorporated into account.move
19+
by the l10n_br_account module (decorator pattern).
20+
21+
Specifically:
22+
- In l10n_br_account, fields from l10n_br_fiscal.document
23+
are added to account.move using Odoo's `_inherits` (composition)
24+
mechanism.
25+
- The methods in *this* mixin, however, are intended to be inherited
26+
using the standard `_inherit` mechanism.
27+
28+
This separation is crucial because `_inherits` handles field composition
29+
but does not inherit methods. Thus, `_inherit` is used to bring in
30+
these methods. If these methods were defined in the same class as the
31+
fields of l10n_br_fiscal.document.mixin (which are subject to
32+
`_inherits`), and account.move.line also used `_inherit` on that
33+
single class, the fields would be duplicated.
34+
"""
35+
1436
_name = "l10n_br_fiscal.document.mixin.methods"
1537
_description = "Fiscal Document Mixin Methods"
1638

@@ -64,7 +86,16 @@ def _onchange_fiscal_operation_id(self):
6486
self.document_subsequent_ids = subsequent_documents
6587

6688
def _get_amount_lines(self):
67-
"""Get object lines instaces used to compute fields"""
89+
"""
90+
Hook method to retrieve the document lines used for amount calculations.
91+
92+
This method should be overridden by models that inherit this mixin
93+
if their fiscal document lines are stored in a field other than
94+
`fiscal_line_ids`. The returned recordset should contain line objects
95+
that have the fiscal amount fields to be summed.
96+
97+
:return: A recordset of fiscal document line objects.
98+
"""
6899
return self.mapped("fiscal_line_ids")
69100

70101
def _get_product_amount_lines(self):
@@ -98,6 +129,17 @@ def _compute_document_serie_id(self):
98129
doc.document_serie_id = False
99130

100131
def _compute_fiscal_amount(self):
132+
"""
133+
Compute and sum various fiscal amounts from the document lines.
134+
135+
This method iterates over fields prefixed with 'amount_' (as determined
136+
by `_get_amount_fields`) and sums corresponding values from the lines
137+
retrieved by `_get_amount_lines`.
138+
139+
It handles cases where delivery costs (freight, insurance, other) are
140+
defined at the document total level rather than per line.
141+
"""
142+
101143
fields = self._get_amount_fields()
102144
for doc in self:
103145
values = {key: 0.0 for key in fields}
@@ -151,12 +193,17 @@ def _document_comment(self):
151193

152194
def _get_fiscal_partner(self):
153195
"""
154-
Meant to be overriden when the l10n_br_fiscal.document partner_id should not
155-
be the same as the sale.order, purchase.order, account.move (...) partner_id.
196+
Hook method to determine the fiscal partner for the document.
156197
157-
(In the case of invoicing, the invoicing partner set by the user should
158-
get priority over any invoicing contact returned by address_get.)
198+
This method is designed to be overridden in implementing models if the
199+
partner relevant for fiscal purposes (e.g., for tax calculations,
200+
final consumer status) is different from the main `partner_id`
201+
of the document record. For instance, an invoice might use a specific
202+
invoicing contact derived from the main partner.
203+
204+
:return: A `res.partner` recordset representing the fiscal partner.
159205
"""
206+
160207
self.ensure_one()
161208
return self.partner_id
162209

0 commit comments

Comments
 (0)