odoo-addon-l10n-br-fiscal 18.0.2.0.0.10__py3-none-any.whl → 18.0.7.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of odoo-addon-l10n-br-fiscal might be problematic. Click here for more details.

Files changed (78) hide show
  1. odoo/addons/l10n_br_fiscal/README.rst +1 -1
  2. odoo/addons/l10n_br_fiscal/__manifest__.py +7 -3
  3. odoo/addons/l10n_br_fiscal/constants/fiscal.py +64 -18
  4. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.cest.csv +1043 -983
  5. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.cst.csv +58 -0
  6. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.document.type.csv +1 -0
  7. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.operation.indicator.csv +27 -0
  8. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.classification.csv +163 -0
  9. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.csv +31 -0
  10. odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.group.csv +3 -0
  11. odoo/addons/l10n_br_fiscal/data/operation_data.xml +1 -1
  12. odoo/addons/l10n_br_fiscal/demo/fiscal_document_demo.xml +3 -179
  13. odoo/addons/l10n_br_fiscal/demo/fiscal_document_nfse_demo.xml +0 -4
  14. odoo/addons/l10n_br_fiscal/demo/fiscal_operation_demo.xml +2 -2
  15. odoo/addons/l10n_br_fiscal/i18n/l10n_br_fiscal.pot +665 -79
  16. odoo/addons/l10n_br_fiscal/i18n/pt_BR.po +713 -102
  17. odoo/addons/l10n_br_fiscal/migrations/18.0.3.0.0/pre-migration.py +30 -0
  18. odoo/addons/l10n_br_fiscal/models/__init__.py +2 -2
  19. odoo/addons/l10n_br_fiscal/models/comment.py +3 -1
  20. odoo/addons/l10n_br_fiscal/models/data_abstract.py +9 -6
  21. odoo/addons/l10n_br_fiscal/models/document.py +27 -8
  22. odoo/addons/l10n_br_fiscal/models/document_line.py +51 -8
  23. odoo/addons/l10n_br_fiscal/models/document_line_mixin.py +1107 -35
  24. odoo/addons/l10n_br_fiscal/models/document_mixin.py +244 -6
  25. odoo/addons/l10n_br_fiscal/models/document_related.py +1 -1
  26. odoo/addons/l10n_br_fiscal/models/document_serie.py +33 -0
  27. odoo/addons/l10n_br_fiscal/models/icms_regulation.py +1 -1
  28. odoo/addons/l10n_br_fiscal/models/operation_dashboard.py +3 -2
  29. odoo/addons/l10n_br_fiscal/models/operation_indicator.py +58 -0
  30. odoo/addons/l10n_br_fiscal/models/operation_line.py +28 -0
  31. odoo/addons/l10n_br_fiscal/models/partner_profile.py +6 -0
  32. odoo/addons/l10n_br_fiscal/models/product_template.py +4 -0
  33. odoo/addons/l10n_br_fiscal/models/res_company.py +17 -0
  34. odoo/addons/l10n_br_fiscal/models/res_partner.py +17 -0
  35. odoo/addons/l10n_br_fiscal/models/simplified_tax_range.py +8 -0
  36. odoo/addons/l10n_br_fiscal/models/tax.py +7 -3
  37. odoo/addons/l10n_br_fiscal/models/tax_classification.py +81 -0
  38. odoo/addons/l10n_br_fiscal/security/fiscal_security.xml +6 -16
  39. odoo/addons/l10n_br_fiscal/security/ir.model.access.csv +7 -2
  40. odoo/addons/l10n_br_fiscal/static/description/index.html +1 -1
  41. odoo/addons/l10n_br_fiscal/tests/__init__.py +2 -0
  42. odoo/addons/l10n_br_fiscal/tests/test_document_edition.py +175 -10
  43. odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_generic.py +13 -42
  44. odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_nfse.py +0 -5
  45. odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_serie.py +60 -0
  46. odoo/addons/l10n_br_fiscal/tests/test_tax_benefit.py +2 -5
  47. odoo/addons/l10n_br_fiscal/tests/test_tax_classification.py +110 -0
  48. odoo/addons/l10n_br_fiscal/views/document_line_mixin_view.xml +107 -4
  49. odoo/addons/l10n_br_fiscal/views/document_line_view.xml +7 -3
  50. odoo/addons/l10n_br_fiscal/views/document_view.xml +34 -15
  51. odoo/addons/l10n_br_fiscal/views/icms_regulation_view.xml +1 -5
  52. odoo/addons/l10n_br_fiscal/views/l10n_br_fiscal_action.xml +30 -0
  53. odoo/addons/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml +16 -9
  54. odoo/addons/l10n_br_fiscal/views/nbs_view.xml +1 -5
  55. odoo/addons/l10n_br_fiscal/views/ncm_view.xml +1 -5
  56. odoo/addons/l10n_br_fiscal/views/operation_dashboard_view.xml +3 -3
  57. odoo/addons/l10n_br_fiscal/views/operation_indicator_view.xml +75 -0
  58. odoo/addons/l10n_br_fiscal/views/operation_line_view.xml +4 -5
  59. odoo/addons/l10n_br_fiscal/views/operation_view.xml +1 -5
  60. odoo/addons/l10n_br_fiscal/views/product_product_view.xml +33 -6
  61. odoo/addons/l10n_br_fiscal/views/product_template_view.xml +22 -4
  62. odoo/addons/l10n_br_fiscal/views/res_company_view.xml +6 -0
  63. odoo/addons/l10n_br_fiscal/views/res_partner_view.xml +10 -0
  64. odoo/addons/l10n_br_fiscal/views/service_type_view.xml +1 -5
  65. odoo/addons/l10n_br_fiscal/views/tax_classification.xml +108 -0
  66. odoo/addons/l10n_br_fiscal/views/tax_definition_view.xml +1 -5
  67. odoo/addons/l10n_br_fiscal/views/tax_view.xml +2 -2
  68. odoo/addons/l10n_br_fiscal/wizards/__init__.py +1 -1
  69. odoo/addons/l10n_br_fiscal/wizards/base_wizard_mixin.py +1 -1
  70. odoo/addons/l10n_br_fiscal/wizards/document_import_wizard.py +234 -0
  71. odoo/addons/l10n_br_fiscal/wizards/{document_import_wizard_mixin.xml → document_import_wizard.xml} +26 -7
  72. {odoo_addon_l10n_br_fiscal-18.0.2.0.0.10.dist-info → odoo_addon_l10n_br_fiscal-18.0.7.1.0.dist-info}/METADATA +3 -3
  73. {odoo_addon_l10n_br_fiscal-18.0.2.0.0.10.dist-info → odoo_addon_l10n_br_fiscal-18.0.7.1.0.dist-info}/RECORD +75 -68
  74. odoo/addons/l10n_br_fiscal/models/document_line_mixin_methods.py +0 -837
  75. odoo/addons/l10n_br_fiscal/models/document_mixin_methods.py +0 -349
  76. odoo/addons/l10n_br_fiscal/wizards/document_import_wizard_mixin.py +0 -129
  77. {odoo_addon_l10n_br_fiscal-18.0.2.0.0.10.dist-info → odoo_addon_l10n_br_fiscal-18.0.7.1.0.dist-info}/WHEEL +0 -0
  78. {odoo_addon_l10n_br_fiscal-18.0.2.0.0.10.dist-info → odoo_addon_l10n_br_fiscal-18.0.7.1.0.dist-info}/top_level.txt +0 -0
@@ -8,7 +8,6 @@ from ..constants.fiscal import (
8
8
  DOCUMENT_ISSUER,
9
9
  DOCUMENT_ISSUER_COMPANY,
10
10
  FINAL_CUSTOMER,
11
- FINAL_CUSTOMER_YES,
12
11
  FISCAL_COMMENT_DOCUMENT,
13
12
  NFE_IND_PRES,
14
13
  NFE_IND_PRES_DEFAULT,
@@ -42,7 +41,6 @@ class FiscalDocumentMixin(models.AbstractModel):
42
41
  """
43
42
 
44
43
  _name = "l10n_br_fiscal.document.mixin"
45
- _inherit = "l10n_br_fiscal.document.mixin.methods"
46
44
  _description = "Document Fiscal Mixin Fields"
47
45
 
48
46
  def _date_server_format(self):
@@ -58,6 +56,218 @@ class FiscalDocumentMixin(models.AbstractModel):
58
56
  )
59
57
  return domain
60
58
 
59
+ def _prepare_br_fiscal_dict(self, default=False):
60
+ self.ensure_one()
61
+ fields = self.env["l10n_br_fiscal.document.mixin"]._fields.keys()
62
+
63
+ # we now read the record fiscal fields except the m2m tax:
64
+ vals = self._convert_to_write(self.read(fields)[0])
65
+
66
+ # remove id field to avoid conflicts
67
+ vals.pop("id", None)
68
+
69
+ if default: # in case you want to use new rather than write later
70
+ return {f"default_{k}": vals[k] for k in vals.keys()}
71
+ return vals
72
+
73
+ @api.onchange("document_type_id")
74
+ def _onchange_document_type_id(self):
75
+ if self.document_type_id and self.issuer == DOCUMENT_ISSUER_COMPANY:
76
+ self.document_serie_id = self.document_type_id.get_document_serie(
77
+ self.company_id, self.fiscal_operation_id
78
+ )
79
+
80
+ @api.depends("fiscal_operation_id")
81
+ def _compute_document_type_id(self):
82
+ for doc in self.filtered(lambda doc: doc.fiscal_operation_id):
83
+ if doc.issuer == DOCUMENT_ISSUER_COMPANY and not doc.document_type_id:
84
+ doc.document_type_id = doc.company_id.document_type_id
85
+
86
+ def _get_amount_lines(self):
87
+ """Get object lines instances used to compute fiscal fields"""
88
+ return self.mapped(self._get_fiscal_lines_field_name())
89
+
90
+ def _get_product_amount_lines(self):
91
+ fiscal_line_ids = self._get_amount_lines()
92
+ return fiscal_line_ids.filtered(lambda line: line.product_id.type != "service")
93
+
94
+ @api.model
95
+ def _get_amount_fields(self):
96
+ """Get all fields with 'amount_' prefix"""
97
+ fields = self.env["l10n_br_fiscal.document.mixin"]._fields.keys()
98
+ prefixes = ("amount_", "fiscal_amount_")
99
+ amount_fields = [f for f in fields if f.startswith(prefixes)]
100
+ return amount_fields
101
+
102
+ @api.depends("document_serie_id", "issuer")
103
+ def _compute_document_serie(self):
104
+ for doc in self:
105
+ if doc.document_serie_id and doc.issuer == DOCUMENT_ISSUER_COMPANY:
106
+ doc.document_serie = doc.document_serie_id.code
107
+ elif doc.document_serie is None:
108
+ doc.document_serie = False
109
+
110
+ @api.depends("document_type_id", "issuer")
111
+ def _compute_document_serie_id(self):
112
+ for doc in self:
113
+ if (
114
+ not doc.document_serie_id
115
+ and doc.document_type_id
116
+ and doc.issuer == DOCUMENT_ISSUER_COMPANY
117
+ ):
118
+ doc.document_serie_id = doc.document_type_id.get_document_serie(
119
+ doc.company_id, doc.fiscal_operation_id
120
+ )
121
+ elif doc.document_serie_id is None:
122
+ doc.document_serie_id = False
123
+
124
+ @api.model
125
+ def _get_fiscal_lines_field_name(self):
126
+ return "fiscal_line_ids"
127
+
128
+ def _get_fiscal_amount_field_dependencies(self):
129
+ """
130
+ Dynamically get the list of field dependencies.
131
+ """
132
+ if self._abstract:
133
+ return []
134
+ o2m_field_name = self._get_fiscal_lines_field_name()
135
+ target_fields = []
136
+ for field in self._get_amount_fields():
137
+ if (
138
+ field.replace("amount_", "")
139
+ in getattr(self, o2m_field_name)._fields.keys()
140
+ ):
141
+ target_fields.append(field.replace("amount_", ""))
142
+
143
+ return [o2m_field_name] + [
144
+ f"{o2m_field_name}.{target_field}" for target_field in target_fields
145
+ ]
146
+
147
+ @api.depends(lambda self: self._get_fiscal_amount_field_dependencies())
148
+ def _compute_fiscal_amount(self):
149
+ """
150
+ Compute and sum various fiscal amounts from the document lines.
151
+
152
+ This method iterates over fields prefixed with 'amount_' (as determined
153
+ by `_get_amount_fields`) and sums corresponding values from the lines
154
+ retrieved by `_get_amount_lines`.
155
+
156
+ It handles cases where delivery costs (freight, insurance, other) are
157
+ defined at the document total level rather than per line.
158
+ """
159
+
160
+ fields = self._get_amount_fields()
161
+ for doc in self.filtered(lambda m: m.fiscal_operation_id):
162
+ values = {key: 0.0 for key in fields}
163
+ for line in doc._get_amount_lines():
164
+ for field in fields:
165
+ if field in line._fields.keys():
166
+ values[field] += line[field]
167
+ if field.replace("amount_", "") in line._fields.keys():
168
+ # FIXME this field creates an error in invoice form
169
+ if field == "amount_financial_discount_value":
170
+ values["amount_financial_discount_value"] += (
171
+ 0 # line.financial_discount_value
172
+ )
173
+ else:
174
+ values[field] += line[field.replace("amount_", "")]
175
+
176
+ # Valores definidos pelo Total e não pela Linha
177
+ if (
178
+ doc.company_id.delivery_costs == "total"
179
+ or doc.force_compute_delivery_costs_by_total
180
+ ):
181
+ values["amount_freight_value"] = doc.amount_freight_value
182
+ values["amount_insurance_value"] = doc.amount_insurance_value
183
+ values["amount_other_value"] = doc.amount_other_value
184
+
185
+ doc.update(values)
186
+
187
+ def _get_fiscal_partner(self):
188
+ """
189
+ Hook method to determine the fiscal partner for the document.
190
+
191
+ This method is designed to be overridden in implementing models if the
192
+ partner relevant for fiscal purposes (e.g., for tax calculations,
193
+ final consumer status) is different from the main `partner_id`
194
+ of the document record. For instance, an invoice might use a specific
195
+ invoicing contact derived from the main partner.
196
+
197
+ :return: A `res.partner` recordset representing the fiscal partner.
198
+ """
199
+
200
+ self.ensure_one()
201
+ return self.partner_id
202
+
203
+ @api.depends("partner_id")
204
+ def _compute_ind_final(self):
205
+ for doc in self:
206
+ partner = doc._get_fiscal_partner()
207
+ if partner:
208
+ doc.ind_final = partner.ind_final
209
+ else:
210
+ # Default Value
211
+ doc.ind_final = "1" # Yes
212
+
213
+ @api.onchange("ind_final")
214
+ def _inverse_ind_final(self):
215
+ for doc in self:
216
+ for line in doc._get_amount_lines():
217
+ if line.ind_final != doc.ind_final:
218
+ line.ind_final = doc.ind_final
219
+
220
+ @api.depends("fiscal_operation_id")
221
+ def _compute_operation_name(self):
222
+ for doc in self:
223
+ if doc.fiscal_operation_id:
224
+ doc.operation_name = doc.fiscal_operation_id.name
225
+ else:
226
+ doc.operation_name = False
227
+
228
+ @api.depends("fiscal_operation_id")
229
+ def _compute_comment_ids(self):
230
+ for doc in self:
231
+ if doc.fiscal_operation_id:
232
+ doc.comment_ids = doc.fiscal_operation_id.comment_ids
233
+ elif doc.comment_ids is None:
234
+ doc.comment_ids = []
235
+
236
+ def _distribute_amount_to_lines(self, amount_field_name, line_field_name):
237
+ for record in self:
238
+ if not (
239
+ record.delivery_costs == "total"
240
+ or record.force_compute_delivery_costs_by_total
241
+ ):
242
+ continue
243
+ lines = record._get_product_amount_lines()
244
+ if not lines:
245
+ continue
246
+ amount_to_distribute = record[amount_field_name]
247
+ total_gross = sum(lines.mapped("price_gross"))
248
+ if total_gross > 0:
249
+ distributed_amount = 0
250
+ for line in lines[:-1]:
251
+ proportional_amount = record.currency_id.round(
252
+ amount_to_distribute * (line.price_gross / total_gross)
253
+ )
254
+ line[line_field_name] = proportional_amount
255
+ distributed_amount += proportional_amount
256
+ lines[-1][line_field_name] = amount_to_distribute - distributed_amount
257
+ else:
258
+ lines.write({line_field_name: 0.0})
259
+ if lines:
260
+ lines[0][line_field_name] = amount_to_distribute
261
+
262
+ def _inverse_amount_freight(self):
263
+ self._distribute_amount_to_lines("amount_freight_value", "freight_value")
264
+
265
+ def _inverse_amount_insurance(self):
266
+ self._distribute_amount_to_lines("amount_insurance_value", "insurance_value")
267
+
268
+ def _inverse_amount_other(self):
269
+ self._distribute_amount_to_lines("amount_other_value", "other_value")
270
+
61
271
  fiscal_operation_id = fields.Many2one(
62
272
  comodel_name="l10n_br_fiscal.operation",
63
273
  string="Operation",
@@ -111,7 +321,11 @@ class FiscalDocumentMixin(models.AbstractModel):
111
321
  ind_final = fields.Selection(
112
322
  selection=FINAL_CUSTOMER,
113
323
  string="Final Consumption Operation",
114
- default=FINAL_CUSTOMER_YES,
324
+ compute="_compute_ind_final",
325
+ inverse="_inverse_ind_final",
326
+ store=True,
327
+ precompute=True,
328
+ readonly=False,
115
329
  )
116
330
 
117
331
  currency_id = fields.Many2one(
@@ -126,7 +340,31 @@ class FiscalDocumentMixin(models.AbstractModel):
126
340
  help="Amount without discount.",
127
341
  )
128
342
 
129
- amount_untaxed = fields.Monetary(
343
+ fiscal_amount_untaxed = fields.Monetary(
344
+ compute="_compute_fiscal_amount",
345
+ store=True,
346
+ )
347
+
348
+ amount_ibs_base = fields.Monetary(
349
+ string="IBS Base",
350
+ compute="_compute_fiscal_amount",
351
+ store=True,
352
+ )
353
+
354
+ amount_ibs_value = fields.Monetary(
355
+ string="IBS Value",
356
+ compute="_compute_fiscal_amount",
357
+ store=True,
358
+ )
359
+
360
+ amount_cbs_base = fields.Monetary(
361
+ string="CBS Base",
362
+ compute="_compute_fiscal_amount",
363
+ store=True,
364
+ )
365
+
366
+ amount_cbs_value = fields.Monetary(
367
+ string="CBS Value",
130
368
  compute="_compute_fiscal_amount",
131
369
  store=True,
132
370
  )
@@ -394,12 +632,12 @@ class FiscalDocumentMixin(models.AbstractModel):
394
632
  store=True,
395
633
  )
396
634
 
397
- amount_tax = fields.Monetary(
635
+ fiscal_amount_tax = fields.Monetary(
398
636
  compute="_compute_fiscal_amount",
399
637
  store=True,
400
638
  )
401
639
 
402
- amount_total = fields.Monetary(
640
+ fiscal_amount_total = fields.Monetary(
403
641
  compute="_compute_fiscal_amount",
404
642
  store=True,
405
643
  )
@@ -104,7 +104,7 @@ class DocumentRelated(models.Model):
104
104
  return False
105
105
 
106
106
  self.document_type_id = related.document_type_id
107
- self.document_total_amount = related.amount_total
107
+ self.document_total_amount = related.fiscal_amount_total
108
108
  self.document_total_weight = related.total_weight
109
109
 
110
110
  if related.document_type_id.electronic:
@@ -3,11 +3,13 @@
3
3
  # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
4
4
 
5
5
  from odoo import _, api, fields, models
6
+ from odoo.exceptions import ValidationError
6
7
 
7
8
  from ..constants.fiscal import (
8
9
  DOCUMENT_ISSUER_COMPANY,
9
10
  FISCAL_IN_OUT,
10
11
  FISCAL_IN_OUT_DEFAULT,
12
+ SITUACAO_EDOC_EM_DIGITACAO,
11
13
  )
12
14
 
13
15
 
@@ -55,6 +57,14 @@ class DocumentSerie(models.Model):
55
57
  string="Invalidate Number Range",
56
58
  )
57
59
 
60
+ _sql_constraints = [
61
+ (
62
+ "document_serie_unique",
63
+ "unique(code, document_type_id, company_id)",
64
+ "A Fiscal Document Serie already exists for this document type.",
65
+ )
66
+ ]
67
+
58
68
  @api.model
59
69
  def _create_sequence(self, values):
60
70
  """Create new no_gap entry sequence for every
@@ -83,6 +93,29 @@ class DocumentSerie(models.Model):
83
93
  for record in self:
84
94
  record.display_name = record.name
85
95
 
96
+ def write(self, vals):
97
+ if "internal_sequence_id" in vals:
98
+ raise ValidationError(_("You cannot change the internal sequence."))
99
+ if "code" in vals:
100
+ for serie in self:
101
+ if serie.code == vals["code"]:
102
+ continue
103
+ if self.env["l10n_br_fiscal.document"].search_count(
104
+ [
105
+ ("document_serie_id", "=", serie.id),
106
+ ("state_edoc", "not in", [SITUACAO_EDOC_EM_DIGITACAO]),
107
+ ],
108
+ limit=1,
109
+ ):
110
+ raise ValidationError(
111
+ _(
112
+ "You cannot change the code of a document "
113
+ "serie %(name)s that is already in use.",
114
+ name=serie.name,
115
+ )
116
+ )
117
+ return super().write(vals)
118
+
86
119
  def _is_invalid_number(self, document_number):
87
120
  self.ensure_one()
88
121
  is_invalid_number = True
@@ -2101,7 +2101,7 @@ class ICMSRegulation(models.Model):
2101
2101
  company.state_id != partner.state_id
2102
2102
  and partner.ind_ie_dest == NFE_IND_IE_DEST_9
2103
2103
  and operation_line.fiscal_operation_type == FISCAL_OUT
2104
- or operation_line.fiscal_operation_id.fiscal_type == "return_in"
2104
+ or operation_line.fiscal_operation_id.fiscal_type != "return_in"
2105
2105
  and operation_line.fiscal_operation_type == FISCAL_IN
2106
2106
  ):
2107
2107
  domain = self._build_map_tax_def_domain(
@@ -127,7 +127,7 @@ class Operation(models.Model):
127
127
  }
128
128
 
129
129
  def open_action(self):
130
- """return action based on type for related journals"""
130
+ """Return action based on type for related journals"""
131
131
 
132
132
  _fiscal_type_map = {
133
133
  "purchase": "in",
@@ -157,7 +157,8 @@ class Operation(models.Model):
157
157
  }
158
158
  )
159
159
 
160
- [action] = self.env.ref("l10n_br_fiscal.{action_name}").read()
160
+ xmlid = f"l10n_br_fiscal.{action_name}"
161
+ [action] = self.env.ref(xmlid).read()
161
162
  action["context"] = ctx
162
163
  action["domain"] = self._context.get("use_domain", [])
163
164
  action["domain"] += [
@@ -0,0 +1,58 @@
1
+ # Copyright (C) 2025 Marcel Savegnago <https://escodoo.com.br>
2
+ # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
3
+
4
+ from odoo import fields, models
5
+
6
+
7
+ class OperationIndicator(models.Model):
8
+ """Operation Indicator
9
+
10
+ This model stores the Operation Indicators (cIndOp) table according to
11
+ Annex VII of Technical Note No. 004/2025 from NFS-e Nacional, which is
12
+ part of the Brazilian Tax Reform (Reforma Tributária do Consumo).
13
+
14
+ The cIndOp field is used in the Service Provision Declaration (DPS)
15
+ to categorize consumption operations, as required by Art. 11 of
16
+ Complementary Law No. 214/2025.
17
+
18
+ This table will become mandatory from January 1, 2026.
19
+ """
20
+
21
+ _name = "l10n_br_fiscal.operation.indicator"
22
+ _inherit = "l10n_br_fiscal.data.abstract"
23
+ _description = "Operation Indicator"
24
+ _order = "code"
25
+
26
+ code = fields.Char(
27
+ string="Operation Indicator Code",
28
+ required=True,
29
+ index=True,
30
+ size=6,
31
+ help="Operation indicator code according to Annex VII of NT 004/2025 "
32
+ "(e.g., 020101, 030101)",
33
+ )
34
+
35
+ operation_type = fields.Text(
36
+ required=True,
37
+ help="Type of operation according to Art. 11 of Complementary Law "
38
+ "No. 214/2025",
39
+ )
40
+
41
+ operation_location = fields.Text(
42
+ string="Operation Location Consideration",
43
+ help="Where the operation is considered to take place according to "
44
+ "the legislation",
45
+ )
46
+
47
+ supply_characteristic = fields.Text(
48
+ help="Specific characteristic of the supply execution that determines "
49
+ "the place of supply",
50
+ )
51
+
52
+ supply_location = fields.Text(
53
+ string="DFe Supply Location",
54
+ required=True,
55
+ help="Place of supply to be identified in the Digital Fiscal Document "
56
+ "(DFe), such as supplier establishment, acquirer address, "
57
+ "recipient address, or other locations depending on the operation",
58
+ )
@@ -37,6 +37,11 @@ class OperationLine(models.Model):
37
37
 
38
38
  document_type_id = fields.Many2one(comodel_name="l10n_br_fiscal.document.type")
39
39
 
40
+ tax_classification_id = fields.Many2one(
41
+ comodel_name="l10n_br_fiscal.tax.classification",
42
+ string="Tax Classification",
43
+ )
44
+
40
45
  cfop_internal_id = fields.Many2one(
41
46
  comodel_name="l10n_br_fiscal.cfop",
42
47
  string="CFOP Internal",
@@ -167,6 +172,13 @@ class OperationLine(models.Model):
167
172
  cfop = self.cfop_export_id
168
173
  return cfop
169
174
 
175
+ def _get_tax_classification(self, company):
176
+ if self.tax_classification_id:
177
+ return self.tax_classification_id
178
+ elif company.tax_classification_id:
179
+ return company.tax_classification_id
180
+ return self.env["l10n_br_fiscal.tax.classification"]
181
+
170
182
  def _build_mapping_result_ipi(self, mapping_result, tax_definition):
171
183
  if tax_definition and tax_definition.ipi_guideline_id:
172
184
  mapping_result["ipi_guideline"] = tax_definition.ipi_guideline_id
@@ -246,12 +258,15 @@ class OperationLine(models.Model):
246
258
  (l10n_br_fiscal.tax.ipi.guideline).
247
259
  - 'icms_tax_benefit_id': The determined ICMS tax benefit record
248
260
  ID (l10n_br_fiscal.tax.definition) or False.
261
+ - 'tax_classification': The determined Tax Classification record
262
+ (l10n_br_fiscal.tax.classification).
249
263
  """
250
264
  mapping_result = {
251
265
  "taxes": {},
252
266
  "cfop": False,
253
267
  "ipi_guideline": self.env.ref("l10n_br_fiscal.tax_guideline_999"),
254
268
  "icms_tax_benefit_id": False,
269
+ "tax_classification": False,
255
270
  }
256
271
 
257
272
  self.ensure_one()
@@ -259,6 +274,9 @@ class OperationLine(models.Model):
259
274
  # Define CFOP
260
275
  mapping_result["cfop"] = self._get_cfop(company, partner)
261
276
 
277
+ # Define Tax Classification
278
+ mapping_result["tax_classification"] = self._get_tax_classification(company)
279
+
262
280
  # 1 Get Tax Defs from Company
263
281
  for tax_definition in company.tax_definition_ids.map_tax_definition(
264
282
  company,
@@ -273,6 +291,16 @@ class OperationLine(models.Model):
273
291
  ):
274
292
  self._build_mapping_result(mapping_result, tax_definition)
275
293
 
294
+ # 1_5 From Tax Classification
295
+ if mapping_result["tax_classification"]:
296
+ mapping_result["taxes"][
297
+ mapping_result["tax_classification"].tax_cbs_id.tax_domain
298
+ ] = mapping_result["tax_classification"].tax_cbs_id
299
+
300
+ mapping_result["taxes"][
301
+ mapping_result["tax_classification"].tax_ibs_id.tax_domain
302
+ ] = mapping_result["tax_classification"].tax_ibs_id
303
+
276
304
  # 2 From NCM
277
305
  if not ncm and product:
278
306
  ncm = product.ncm_id
@@ -8,6 +8,7 @@ from odoo.exceptions import ValidationError
8
8
  from ..constants.fiscal import (
9
9
  NFE_IND_IE_DEST,
10
10
  NFE_IND_IE_DEST_DEFAULT,
11
+ PUBLIC_ENTIRY_TYPE,
11
12
  TAX_FRAMEWORK,
12
13
  TAX_FRAMEWORK_NORMAL,
13
14
  )
@@ -32,6 +33,11 @@ class PartnerProfile(models.Model):
32
33
  "other government-controlled organizations.",
33
34
  )
34
35
 
36
+ public_entity_type = fields.Selection(
37
+ selection=PUBLIC_ENTIRY_TYPE,
38
+ string="Tipo de Entidade Governamental",
39
+ )
40
+
35
41
  default = fields.Boolean(string="Default Profile", default=True)
36
42
 
37
43
  ind_ie_dest = fields.Selection(
@@ -106,6 +106,10 @@ class ProductTemplate(models.Model):
106
106
  comodel_name="l10n_br_fiscal.nbs", index=True, string="NBS"
107
107
  )
108
108
 
109
+ operation_indicator_id = fields.Many2one(
110
+ comodel_name="l10n_br_fiscal.operation.indicator",
111
+ )
112
+
109
113
  cest_id = fields.Many2one(
110
114
  comodel_name="l10n_br_fiscal.cest",
111
115
  index=True,
@@ -14,10 +14,12 @@ from ..constants.fiscal import (
14
14
  PROCESSADOR_NENHUM,
15
15
  PROFIT_CALCULATION,
16
16
  PROFIT_CALCULATION_PRESUMED,
17
+ TAX_DOMAIN_CBS,
17
18
  TAX_DOMAIN_COFINS,
18
19
  TAX_DOMAIN_COFINS_WH,
19
20
  TAX_DOMAIN_CSLL,
20
21
  TAX_DOMAIN_CSLL_WH,
22
+ TAX_DOMAIN_IBS,
21
23
  TAX_DOMAIN_ICMS,
22
24
  TAX_DOMAIN_ICMS_SN,
23
25
  TAX_DOMAIN_INSS,
@@ -297,6 +299,11 @@ class ResCompany(models.Model):
297
299
  domain=[("tax_domain", "=", TAX_DOMAIN_INSS_WH)],
298
300
  )
299
301
 
302
+ tax_classification_id = fields.Many2one(
303
+ comodel_name="l10n_br_fiscal.tax.classification",
304
+ string="Default Tax Classification",
305
+ )
306
+
300
307
  tax_definition_ids = fields.One2many(
301
308
  comodel_name="l10n_br_fiscal.tax.definition",
302
309
  inverse_name="company_id",
@@ -377,6 +384,7 @@ class ResCompany(models.Model):
377
384
  self.tax_icms_id = False
378
385
 
379
386
  self._onchange_piscofins_id()
387
+ self._onchange_tax_classification_id()
380
388
  self._onchange_ripi()
381
389
  self._onchange_tax_ipi_id()
382
390
  self._onchange_tax_icms_id()
@@ -502,3 +510,12 @@ class ResCompany(models.Model):
502
510
  self._set_tax_definition(self.tax_inss_wh_id)
503
511
  else:
504
512
  self._del_tax_definition(TAX_DOMAIN_INSS_WH)
513
+
514
+ @api.onchange("tax_classification_id")
515
+ def _onchange_tax_classification_id(self):
516
+ if self.tax_classification_id:
517
+ self._set_tax_definition(self.tax_classification_id.tax_cbs_id)
518
+ self._set_tax_definition(self.tax_classification_id.tax_ibs_id)
519
+ else:
520
+ self._del_tax_definition(TAX_DOMAIN_CBS)
521
+ self._del_tax_definition(TAX_DOMAIN_IBS)
@@ -10,6 +10,7 @@ from ..constants.fiscal import (
10
10
  NFE_IND_IE_DEST,
11
11
  NFE_IND_IE_DEST_9,
12
12
  NFE_IND_IE_DEST_DEFAULT,
13
+ PUBLIC_ENTIRY_TYPE,
13
14
  TAX_FRAMEWORK,
14
15
  TAX_FRAMEWORK_NORMAL,
15
16
  )
@@ -76,6 +77,11 @@ class ResPartner(models.Model):
76
77
  "other government-controlled organizations.",
77
78
  )
78
79
 
80
+ public_entity_type = fields.Selection(
81
+ selection=PUBLIC_ENTIRY_TYPE,
82
+ string="Tipo de Entidade Governamental",
83
+ )
84
+
79
85
  ind_final = fields.Selection(
80
86
  selection=FINAL_CUSTOMER,
81
87
  string="Final Consumption Operation",
@@ -109,6 +115,16 @@ class ResPartner(models.Model):
109
115
 
110
116
  rntrc_code = fields.Char(string="RNTRC Code", size=12, tracking=True)
111
117
 
118
+ nif_motive_absence = fields.Selection(
119
+ selection=[
120
+ ("0", "Not informed in the origin note"),
121
+ ("1", "Exemption from NIF"),
122
+ ("2", "NIF not required"),
123
+ ],
124
+ default=False,
125
+ string="NIF motive absence",
126
+ )
127
+
112
128
  def _inverse_fiscal_profile(self):
113
129
  for p in self:
114
130
  p._onchange_fiscal_profile_id()
@@ -125,6 +141,7 @@ class ResPartner(models.Model):
125
141
  p.tax_framework = p.fiscal_profile_id.tax_framework
126
142
  p.ind_ie_dest = p.fiscal_profile_id.ind_ie_dest
127
143
  p.is_public_entity = p.fiscal_profile_id.is_public_entity
144
+ p.public_entity_type = p.fiscal_profile_id.public_entity_type
128
145
 
129
146
  @api.onchange("ind_ie_dest")
130
147
  def _onchange_ind_ie_dest(self):
@@ -66,3 +66,11 @@ class SimplifiedTaxRange(models.Model):
66
66
  tax_pis_percent = fields.Float(
67
67
  string="Tax PIS Percent", digits="Fiscal Tax Percent"
68
68
  )
69
+
70
+ tax_ibs_percent = fields.Float(
71
+ string="Tax IBS Percent", digits="Fiscal Tax Percent"
72
+ )
73
+
74
+ tax_cbs_percent = fields.Float(
75
+ string="Tax CBS Percent", digits="Fiscal Tax Percent"
76
+ )
@@ -454,9 +454,13 @@ class Tax(models.Model):
454
454
  and cfop.destination == CFOP_DESTINATION_EXTERNAL
455
455
  and partner.ind_ie_dest == NFE_IND_IE_DEST_9
456
456
  and tax_dict.get("tax_value")
457
- and operation_line.fiscal_operation_type == FISCAL_OUT
458
- or operation_line.fiscal_operation_id.fiscal_type == "return_in"
459
- and operation_line.fiscal_operation_type == FISCAL_IN
457
+ and (
458
+ operation_line.fiscal_operation_type == FISCAL_OUT
459
+ or (
460
+ operation_line.fiscal_operation_type == FISCAL_IN
461
+ and operation_line.fiscal_operation_id.fiscal_type != "return_in"
462
+ )
463
+ )
460
464
  ):
461
465
  icms_tax_difal, _ = company.icms_regulation_id.map_tax_def_icms_difal(
462
466
  company, partner, product, ncm, nbm, cest, operation_line, ind_final