odoo-addon-l10n-br-fiscal 16.0.2.17.0__py3-none-any.whl → 16.0.19.4.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.
- odoo/addons/l10n_br_fiscal/README.rst +11 -4
- odoo/addons/l10n_br_fiscal/__manifest__.py +20 -12
- odoo/addons/l10n_br_fiscal/constants/fiscal.py +64 -18
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.cest.csv +1043 -983
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.cfop.csv +620 -620
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.cst.csv +58 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.document.type.csv +1 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.legal.nature.csv +82 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.nbs.csv +791 -764
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.operation.indicator.csv +27 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.partner.profile.csv +11 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.classification.csv +163 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.csv +32 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal.tax.group.csv +3 -0
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal_icms_tax_definition_data.xml +340 -352
- odoo/addons/l10n_br_fiscal/data/operation_data.xml +1 -1
- odoo/addons/l10n_br_fiscal/data/simplified_tax_data.xml +5 -5
- odoo/addons/l10n_br_fiscal/data/uom.alias.csv +25 -0
- odoo/addons/l10n_br_fiscal/data/uom_data.xml +104 -33
- odoo/addons/l10n_br_fiscal/demo/__init__.py +21 -15
- odoo/addons/l10n_br_fiscal/demo/company_demo.xml +6 -0
- odoo/addons/l10n_br_fiscal/demo/fiscal_document_demo.xml +3 -377
- odoo/addons/l10n_br_fiscal/demo/fiscal_document_nfse_demo.xml +0 -12
- odoo/addons/l10n_br_fiscal/demo/fiscal_operation_demo.xml +2 -2
- odoo/addons/l10n_br_fiscal/demo/icms_tax_definition_demo.xml +5 -2
- odoo/addons/l10n_br_fiscal/demo/res_users_demo.xml +2 -2
- odoo/addons/l10n_br_fiscal/i18n/l10n_br_fiscal.pot +1161 -804
- odoo/addons/l10n_br_fiscal/i18n/pt_BR.po +22 -22
- odoo/addons/l10n_br_fiscal/migrations/16.0.13.0.0/pre-migration.py +25 -0
- odoo/addons/l10n_br_fiscal/migrations/16.0.14.0.0/pre-migration.py +30 -0
- odoo/addons/l10n_br_fiscal/migrations/16.0.14.0.5/pre-migration.py +15 -0
- odoo/addons/l10n_br_fiscal/migrations/16.0.4.0.0/pre-migration.py +220 -0
- odoo/addons/l10n_br_fiscal/migrations/16.0.5.0.0/pre-migration.py +33 -0
- odoo/addons/l10n_br_fiscal/migrations/16.0.5.2.0/pre-migration.py +21 -0
- odoo/addons/l10n_br_fiscal/models/__init__.py +3 -8
- odoo/addons/l10n_br_fiscal/models/cest.py +0 -8
- odoo/addons/l10n_br_fiscal/models/cfop.py +91 -0
- odoo/addons/l10n_br_fiscal/models/city_taxation_code.py +1 -3
- odoo/addons/l10n_br_fiscal/models/comment.py +2 -2
- odoo/addons/l10n_br_fiscal/models/cst.py +0 -1
- odoo/addons/l10n_br_fiscal/models/data_abstract.py +26 -0
- odoo/addons/l10n_br_fiscal/models/data_ncm_nbs_abstract.py +1 -1
- odoo/addons/l10n_br_fiscal/models/document.py +131 -222
- odoo/addons/l10n_br_fiscal/models/document_line.py +82 -5
- odoo/addons/l10n_br_fiscal/models/document_line_mixin.py +1952 -138
- odoo/addons/l10n_br_fiscal/models/document_mixin.py +741 -6
- odoo/addons/l10n_br_fiscal/models/document_related.py +12 -9
- odoo/addons/l10n_br_fiscal/models/document_serie.py +33 -0
- odoo/addons/l10n_br_fiscal/models/document_type.py +0 -6
- odoo/addons/l10n_br_fiscal/models/ibpt.py +1 -1
- odoo/addons/l10n_br_fiscal/models/icms_regulation.py +2 -2
- odoo/addons/l10n_br_fiscal/models/invalidate_number.py +4 -5
- odoo/addons/l10n_br_fiscal/models/legal_nature.py +20 -0
- odoo/addons/l10n_br_fiscal/models/nbm.py +0 -8
- odoo/addons/l10n_br_fiscal/models/ncm.py +0 -12
- odoo/addons/l10n_br_fiscal/models/operation.py +49 -15
- odoo/addons/l10n_br_fiscal/models/operation_dashboard.py +3 -2
- odoo/addons/l10n_br_fiscal/models/operation_indicator.py +58 -0
- odoo/addons/l10n_br_fiscal/models/operation_line.py +75 -6
- odoo/addons/l10n_br_fiscal/models/partner_profile.py +6 -0
- odoo/addons/l10n_br_fiscal/models/product_mixin.py +24 -21
- odoo/addons/l10n_br_fiscal/models/product_template.py +23 -13
- odoo/addons/l10n_br_fiscal/models/res_company.py +31 -9
- odoo/addons/l10n_br_fiscal/models/res_partner.py +38 -6
- odoo/addons/l10n_br_fiscal/models/simplified_tax.py +0 -3
- odoo/addons/l10n_br_fiscal/models/simplified_tax_range.py +8 -0
- odoo/addons/l10n_br_fiscal/models/tax.py +144 -55
- odoo/addons/l10n_br_fiscal/models/tax_classification.py +81 -0
- odoo/addons/l10n_br_fiscal/models/tax_definition.py +72 -23
- odoo/addons/l10n_br_fiscal/models/tax_pis_cofins.py +0 -3
- odoo/addons/l10n_br_fiscal/models/tax_pis_cofins_base.py +1 -1
- odoo/addons/l10n_br_fiscal/models/tax_pis_cofins_credit.py +1 -1
- odoo/addons/l10n_br_fiscal/models/uom_uom.py +15 -30
- odoo/addons/l10n_br_fiscal/security/fiscal_security.xml +11 -27
- odoo/addons/l10n_br_fiscal/security/ir.model.access.csv +11 -10
- odoo/addons/l10n_br_fiscal/static/description/index.html +27 -21
- odoo/addons/l10n_br_fiscal/static/src/js/list_renderer_with_button.esm.js +38 -0
- odoo/addons/l10n_br_fiscal/tests/__init__.py +3 -2
- odoo/addons/l10n_br_fiscal/tests/test_document_edition.py +308 -0
- odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_generic.py +23 -129
- odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_nfse.py +5 -15
- odoo/addons/l10n_br_fiscal/tests/test_fiscal_document_serie.py +60 -0
- odoo/addons/l10n_br_fiscal/tests/test_ibpt.py +4 -3
- odoo/addons/l10n_br_fiscal/tests/test_icms_regulation.py +2 -2
- odoo/addons/l10n_br_fiscal/tests/test_ncm.py +4 -1
- odoo/addons/l10n_br_fiscal/tests/test_tax_benefit.py +17 -22
- odoo/addons/l10n_br_fiscal/tests/test_tax_classification.py +110 -0
- odoo/addons/l10n_br_fiscal/tools.py +1 -1
- odoo/addons/l10n_br_fiscal/views/cest_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/cfop_view.xml +25 -5
- odoo/addons/l10n_br_fiscal/views/city_taxation_code.xml +1 -4
- odoo/addons/l10n_br_fiscal/views/cnae_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/comment_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/cst_view.xml +6 -8
- odoo/addons/l10n_br_fiscal/views/{document_fiscal_line_mixin_view.xml → document_line_mixin_view.xml} +525 -385
- odoo/addons/l10n_br_fiscal/views/document_line_view.xml +101 -82
- odoo/addons/l10n_br_fiscal/views/document_related_view.xml +44 -46
- odoo/addons/l10n_br_fiscal/views/document_serie_view.xml +2 -6
- odoo/addons/l10n_br_fiscal/views/document_type_view.xml +0 -8
- odoo/addons/l10n_br_fiscal/views/document_view.xml +303 -370
- odoo/addons/l10n_br_fiscal/views/icms_regulation_view.xml +14 -16
- odoo/addons/l10n_br_fiscal/views/icms_relief_view.xml +8 -10
- odoo/addons/l10n_br_fiscal/views/invalidate_number_view.xml +46 -48
- odoo/addons/l10n_br_fiscal/views/l10n_br_fiscal_action.xml +166 -280
- odoo/addons/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml +25 -99
- odoo/addons/l10n_br_fiscal/views/legal_nature_view.xml +40 -0
- odoo/addons/l10n_br_fiscal/views/nbm_view.xml +5 -6
- odoo/addons/l10n_br_fiscal/views/nbs_view.xml +5 -6
- odoo/addons/l10n_br_fiscal/views/ncm_view.xml +12 -15
- odoo/addons/l10n_br_fiscal/views/operation_dashboard_view.xml +13 -12
- odoo/addons/l10n_br_fiscal/views/operation_indicator_view.xml +75 -0
- odoo/addons/l10n_br_fiscal/views/operation_line_view.xml +22 -21
- odoo/addons/l10n_br_fiscal/views/operation_view.xml +4 -19
- odoo/addons/l10n_br_fiscal/views/partner_profile_view.xml +3 -6
- odoo/addons/l10n_br_fiscal/views/product_genre_view.xml +7 -9
- odoo/addons/l10n_br_fiscal/views/product_product_view.xml +37 -14
- odoo/addons/l10n_br_fiscal/views/product_template_view.xml +34 -14
- odoo/addons/l10n_br_fiscal/views/res_company_view.xml +55 -52
- odoo/addons/l10n_br_fiscal/views/res_config_settings_view.xml +23 -28
- odoo/addons/l10n_br_fiscal/views/res_partner_view.xml +22 -2
- odoo/addons/l10n_br_fiscal/views/service_type_view.xml +7 -8
- odoo/addons/l10n_br_fiscal/views/simplified_tax_range_view.xml +0 -2
- odoo/addons/l10n_br_fiscal/views/simplified_tax_view.xml +0 -2
- odoo/addons/l10n_br_fiscal/views/tax_classification.xml +110 -0
- odoo/addons/l10n_br_fiscal/views/tax_definition_view.xml +157 -129
- odoo/addons/l10n_br_fiscal/views/tax_estimate_view.xml +0 -2
- odoo/addons/l10n_br_fiscal/views/tax_group_view.xml +3 -6
- odoo/addons/l10n_br_fiscal/views/tax_ipi_control_seal_view.xml +0 -2
- odoo/addons/l10n_br_fiscal/views/tax_ipi_guideline_class_view.xml +0 -2
- odoo/addons/l10n_br_fiscal/views/tax_ipi_guideline_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/tax_pis_cofins_base_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/tax_pis_cofins_credit_view.xml +2 -4
- odoo/addons/l10n_br_fiscal/views/tax_pis_cofins_view.xml +5 -7
- odoo/addons/l10n_br_fiscal/views/tax_view.xml +5 -7
- odoo/addons/l10n_br_fiscal/views/uom_uom.xml +24 -17
- odoo/addons/l10n_br_fiscal/wizards/__init__.py +1 -0
- odoo/addons/l10n_br_fiscal/wizards/base_wizard_mixin.py +1 -1
- odoo/addons/l10n_br_fiscal/wizards/document_import_wizard_mixin.py +129 -0
- odoo/addons/l10n_br_fiscal/wizards/document_import_wizard_mixin.xml +41 -0
- {odoo_addon_l10n_br_fiscal-16.0.2.17.0.dist-info → odoo_addon_l10n_br_fiscal-16.0.19.4.0.dist-info}/METADATA +15 -6
- odoo_addon_l10n_br_fiscal-16.0.19.4.0.dist-info/RECORD +210 -0
- {odoo_addon_l10n_br_fiscal-16.0.2.17.0.dist-info → odoo_addon_l10n_br_fiscal-16.0.19.4.0.dist-info}/WHEEL +1 -1
- odoo/addons/l10n_br_fiscal/data/l10n_br_fiscal_email_template.xml +0 -68
- odoo/addons/l10n_br_fiscal/data/partner_profile_data.xml +0 -96
- odoo/addons/l10n_br_fiscal/data/uom_alternative_data.xml +0 -58
- odoo/addons/l10n_br_fiscal/demo/l10n_br_fiscal_document_email.xml +0 -54
- odoo/addons/l10n_br_fiscal/demo/subsequent_operation_demo.xml +0 -10
- odoo/addons/l10n_br_fiscal/models/document_email.py +0 -74
- odoo/addons/l10n_br_fiscal/models/document_line_mixin_methods.py +0 -913
- odoo/addons/l10n_br_fiscal/models/document_mixin_fields.py +0 -473
- odoo/addons/l10n_br_fiscal/models/document_mixin_methods.py +0 -269
- odoo/addons/l10n_br_fiscal/models/document_move_mixin.py +0 -261
- odoo/addons/l10n_br_fiscal/models/subsequent_document.py +0 -203
- odoo/addons/l10n_br_fiscal/models/subsequent_operation.py +0 -54
- odoo/addons/l10n_br_fiscal/models/uom_uom_alternative.py +0 -22
- odoo/addons/l10n_br_fiscal/tests/test_subsequent_operation.py +0 -71
- odoo/addons/l10n_br_fiscal/tests/test_uom_uom.py +0 -22
- odoo/addons/l10n_br_fiscal/views/document_email_view.xml +0 -48
- odoo/addons/l10n_br_fiscal/views/subsequent_document_view.xml +0 -43
- odoo/addons/l10n_br_fiscal/views/subsequent_operation_view.xml +0 -21
- odoo_addon_l10n_br_fiscal-16.0.2.17.0.dist-info/RECORD +0 -205
- {odoo_addon_l10n_br_fiscal-16.0.2.17.0.dist-info → odoo_addon_l10n_br_fiscal-16.0.19.4.0.dist-info}/top_level.txt +0 -0
|
@@ -1,913 +0,0 @@
|
|
|
1
|
-
# Copyright (C) 2019 Renato Lima - Akretion <renato.lima@akretion.com.br>
|
|
2
|
-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
|
3
|
-
|
|
4
|
-
from copy import deepcopy
|
|
5
|
-
|
|
6
|
-
from lxml import etree
|
|
7
|
-
|
|
8
|
-
from odoo import api, models
|
|
9
|
-
|
|
10
|
-
from ..constants.fiscal import CFOP_DESTINATION_EXPORT, FISCAL_IN
|
|
11
|
-
from ..constants.icms import ICMS_BASE_TYPE_DEFAULT, ICMS_ST_BASE_TYPE_DEFAULT
|
|
12
|
-
from .tax import TAX_DICT_VALUES
|
|
13
|
-
|
|
14
|
-
FISCAL_TAX_ID_FIELDS = [
|
|
15
|
-
"cofins_tax_id",
|
|
16
|
-
"cofins_wh_tax_id",
|
|
17
|
-
"cofinsst_tax_id",
|
|
18
|
-
"csll_tax_id",
|
|
19
|
-
"csll_wh_tax_id",
|
|
20
|
-
"icms_tax_id",
|
|
21
|
-
"icmsfcp_tax_id",
|
|
22
|
-
"icmssn_tax_id",
|
|
23
|
-
"icmsst_tax_id",
|
|
24
|
-
"icmsfcpst_tax_id",
|
|
25
|
-
"ii_tax_id",
|
|
26
|
-
"inss_tax_id",
|
|
27
|
-
"inss_wh_tax_id",
|
|
28
|
-
"ipi_tax_id",
|
|
29
|
-
"irpj_tax_id",
|
|
30
|
-
"irpj_wh_tax_id",
|
|
31
|
-
"issqn_tax_id",
|
|
32
|
-
"issqn_wh_tax_id",
|
|
33
|
-
"pis_tax_id",
|
|
34
|
-
"pis_wh_tax_id",
|
|
35
|
-
"pisst_tax_id",
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
FISCAL_CST_ID_FIELDS = [
|
|
39
|
-
"icms_cst_id",
|
|
40
|
-
"ipi_cst_id",
|
|
41
|
-
"pis_cst_id",
|
|
42
|
-
"pisst_cst_id",
|
|
43
|
-
"cofins_cst_id",
|
|
44
|
-
"cofinsst_cst_id",
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class FiscalDocumentLineMixinMethods(models.AbstractModel):
|
|
49
|
-
_name = "l10n_br_fiscal.document.line.mixin.methods"
|
|
50
|
-
_description = "Fiscal Document Mixin Methods"
|
|
51
|
-
|
|
52
|
-
@api.model
|
|
53
|
-
def inject_fiscal_fields(
|
|
54
|
-
self,
|
|
55
|
-
doc,
|
|
56
|
-
view_ref="l10n_br_fiscal.document_fiscal_line_mixin_form",
|
|
57
|
-
xpath_mappings=None,
|
|
58
|
-
):
|
|
59
|
-
"""
|
|
60
|
-
Inject common fiscal fields into view placeholder elements.
|
|
61
|
-
Used for invoice line, sale order line, purchase order line...
|
|
62
|
-
"""
|
|
63
|
-
fiscal_view = self.env.ref(
|
|
64
|
-
"l10n_br_fiscal.document_fiscal_line_mixin_form"
|
|
65
|
-
).sudo()
|
|
66
|
-
fsc_doc = etree.fromstring(
|
|
67
|
-
fiscal_view.with_context(inherit_branding=True).get_combined_arch()
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
if xpath_mappings is None:
|
|
71
|
-
xpath_mappings = (
|
|
72
|
-
# (placeholder_xpath, fiscal_xpath)
|
|
73
|
-
(".//group[@name='fiscal_fields']", "//group[@name='fiscal_fields']"),
|
|
74
|
-
(".//page[@name='fiscal_taxes']", "//page[@name='fiscal_taxes']"),
|
|
75
|
-
(
|
|
76
|
-
".//page[@name='fiscal_line_extra_info']",
|
|
77
|
-
"//page[@name='fiscal_line_extra_info']",
|
|
78
|
-
),
|
|
79
|
-
# these will only collect (invisible) fields for onchanges:
|
|
80
|
-
(
|
|
81
|
-
".//control[@name='fiscal_taxes_fields']...",
|
|
82
|
-
"//page[@name='fiscal_taxes']//field",
|
|
83
|
-
),
|
|
84
|
-
(
|
|
85
|
-
".//control[@name='fiscal_line_extra_info_fields']...",
|
|
86
|
-
"//page[@name='fiscal_line_extra_info']//field",
|
|
87
|
-
),
|
|
88
|
-
)
|
|
89
|
-
for placeholder_xpath, fiscal_xpath in xpath_mappings:
|
|
90
|
-
fiscal_nodes = fsc_doc.xpath(fiscal_xpath)
|
|
91
|
-
for target_node in doc.findall(placeholder_xpath):
|
|
92
|
-
if len(fiscal_nodes) == 1:
|
|
93
|
-
# replace unique placeholder
|
|
94
|
-
# (deepcopy is required to inject fiscal nodes in possible
|
|
95
|
-
# next places)
|
|
96
|
-
replace_node = deepcopy(fiscal_nodes[0])
|
|
97
|
-
target_node.getparent().replace(target_node, replace_node)
|
|
98
|
-
else:
|
|
99
|
-
# append multiple fields to placeholder container
|
|
100
|
-
for fiscal_node in fiscal_nodes:
|
|
101
|
-
field = deepcopy(fiscal_node)
|
|
102
|
-
if not field.attrib.get("optional"):
|
|
103
|
-
field.attrib["invisible"] = "1"
|
|
104
|
-
target_node.append(field)
|
|
105
|
-
return doc
|
|
106
|
-
|
|
107
|
-
@api.model
|
|
108
|
-
def _get_view(self, view_id=None, view_type="form", **options):
|
|
109
|
-
arch, view = super()._get_view(view_id, view_type, **options)
|
|
110
|
-
if view_type == "form":
|
|
111
|
-
arch = self.inject_fiscal_fields(arch)
|
|
112
|
-
return arch, view
|
|
113
|
-
|
|
114
|
-
@api.depends(
|
|
115
|
-
"fiscal_price",
|
|
116
|
-
"discount_value",
|
|
117
|
-
"insurance_value",
|
|
118
|
-
"other_value",
|
|
119
|
-
"freight_value",
|
|
120
|
-
"fiscal_quantity",
|
|
121
|
-
"amount_tax_not_included",
|
|
122
|
-
"amount_tax_included",
|
|
123
|
-
"amount_tax_withholding",
|
|
124
|
-
"uot_id",
|
|
125
|
-
"product_id",
|
|
126
|
-
"partner_id",
|
|
127
|
-
"company_id",
|
|
128
|
-
"price_unit",
|
|
129
|
-
"quantity",
|
|
130
|
-
"icms_relief_id",
|
|
131
|
-
"fiscal_operation_line_id",
|
|
132
|
-
)
|
|
133
|
-
def _compute_fiscal_amounts(self):
|
|
134
|
-
for record in self:
|
|
135
|
-
round_curr = record.currency_id or self.env.ref("base.BRL")
|
|
136
|
-
|
|
137
|
-
# Total value of products or services
|
|
138
|
-
record.price_gross = round_curr.round(record.price_unit * record.quantity)
|
|
139
|
-
record.amount_fiscal = record.price_gross - record.discount_value
|
|
140
|
-
record.amount_tax = record.amount_tax_not_included
|
|
141
|
-
|
|
142
|
-
add_to_amount = sum(record[a] for a in record._add_fields_to_amount())
|
|
143
|
-
rm_to_amount = sum(record[r] for r in record._rm_fields_to_amount())
|
|
144
|
-
record.amount_untaxed = (
|
|
145
|
-
record.price_gross
|
|
146
|
-
- record.discount_value
|
|
147
|
-
+ add_to_amount
|
|
148
|
-
- rm_to_amount
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
# Valor do documento (NF)
|
|
152
|
-
record.amount_total = record.amount_untaxed + record.amount_tax
|
|
153
|
-
|
|
154
|
-
# Valor Liquido (TOTAL + IMPOSTOS - RETENÇÕES)
|
|
155
|
-
record.amount_taxed = record.amount_total - record.amount_tax_withholding
|
|
156
|
-
|
|
157
|
-
# Valor do documento (NF) - RETENÇÕES
|
|
158
|
-
record.amount_total = record.amount_taxed
|
|
159
|
-
|
|
160
|
-
# Valor financeiro
|
|
161
|
-
if (
|
|
162
|
-
record.fiscal_operation_line_id
|
|
163
|
-
and record.fiscal_operation_line_id.add_to_amount
|
|
164
|
-
and (not record.cfop_id or record.cfop_id.finance_move)
|
|
165
|
-
):
|
|
166
|
-
record.financial_total = record.amount_taxed
|
|
167
|
-
record.financial_total_gross = (
|
|
168
|
-
record.financial_total + record.discount_value
|
|
169
|
-
)
|
|
170
|
-
record.financial_discount_value = record.discount_value
|
|
171
|
-
else:
|
|
172
|
-
record.financial_total_gross = record.financial_total = 0.0
|
|
173
|
-
record.financial_discount_value = 0.0
|
|
174
|
-
|
|
175
|
-
def _compute_taxes(self, taxes, cst=None):
|
|
176
|
-
self.ensure_one()
|
|
177
|
-
return taxes.compute_taxes(
|
|
178
|
-
company=self.company_id,
|
|
179
|
-
partner=self._get_fiscal_partner(),
|
|
180
|
-
product=self.product_id,
|
|
181
|
-
price_unit=self.price_unit,
|
|
182
|
-
quantity=self.quantity,
|
|
183
|
-
uom_id=self.uom_id,
|
|
184
|
-
fiscal_price=self.fiscal_price,
|
|
185
|
-
fiscal_quantity=self.fiscal_quantity,
|
|
186
|
-
uot_id=self.uot_id,
|
|
187
|
-
discount_value=self.discount_value,
|
|
188
|
-
insurance_value=self.insurance_value,
|
|
189
|
-
ii_customhouse_charges=self.ii_customhouse_charges,
|
|
190
|
-
ii_iof_value=self.ii_iof_value,
|
|
191
|
-
other_value=self.other_value,
|
|
192
|
-
freight_value=self.freight_value,
|
|
193
|
-
ncm=self.ncm_id,
|
|
194
|
-
nbs=self.nbs_id,
|
|
195
|
-
nbm=self.nbm_id,
|
|
196
|
-
cest=self.cest_id,
|
|
197
|
-
operation_line=self.fiscal_operation_line_id,
|
|
198
|
-
cfop=self.cfop_id,
|
|
199
|
-
icmssn_range=self.icmssn_range_id,
|
|
200
|
-
icms_origin=self.icms_origin,
|
|
201
|
-
icms_cst_id=self.icms_cst_id,
|
|
202
|
-
ind_final=self.ind_final,
|
|
203
|
-
icms_relief_id=self.icms_relief_id,
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
@api.depends("tax_icms_or_issqn", "partner_is_public_entity")
|
|
207
|
-
def _compute_allow_csll_irpj(self):
|
|
208
|
-
"""Calculates the possibility of 'CSLL' and 'IRPJ' tax charges."""
|
|
209
|
-
for line in self:
|
|
210
|
-
# Determine if 'CSLL' and 'IRPJ' taxes may apply:
|
|
211
|
-
# 1. When providing services (tax_icms_or_issqn == "issqn")
|
|
212
|
-
# 2. When supplying products to public entities (partner_is_public_entity
|
|
213
|
-
# is True)
|
|
214
|
-
if line.tax_icms_or_issqn == "issqn" or line.partner_is_public_entity:
|
|
215
|
-
line.allow_csll_irpj = True # Tax charges may apply
|
|
216
|
-
else:
|
|
217
|
-
line.allow_csll_irpj = False # No tax charges expected
|
|
218
|
-
|
|
219
|
-
def _prepare_br_fiscal_dict(self, default=False):
|
|
220
|
-
self.ensure_one()
|
|
221
|
-
fields = self.env["l10n_br_fiscal.document.line.mixin"]._fields.keys()
|
|
222
|
-
|
|
223
|
-
# we now read the record fiscal fields except the m2m tax:
|
|
224
|
-
vals = self._convert_to_write(self.read(fields)[0])
|
|
225
|
-
|
|
226
|
-
# remove id field to avoid conflicts
|
|
227
|
-
vals.pop("id", None)
|
|
228
|
-
|
|
229
|
-
if default: # in case you want to use new rather than write later
|
|
230
|
-
return {f"default_{k}": vals[k] for k in vals.keys()}
|
|
231
|
-
return vals
|
|
232
|
-
|
|
233
|
-
def _get_all_tax_id_fields(self):
|
|
234
|
-
self.ensure_one()
|
|
235
|
-
taxes = self.env["l10n_br_fiscal.tax"]
|
|
236
|
-
|
|
237
|
-
for fiscal_tax_field in FISCAL_TAX_ID_FIELDS:
|
|
238
|
-
taxes |= self[fiscal_tax_field]
|
|
239
|
-
|
|
240
|
-
return taxes
|
|
241
|
-
|
|
242
|
-
def _remove_all_fiscal_tax_ids(self):
|
|
243
|
-
for line in self:
|
|
244
|
-
to_update = {"fiscal_tax_ids": False}
|
|
245
|
-
for fiscal_tax_field in FISCAL_TAX_ID_FIELDS:
|
|
246
|
-
to_update[fiscal_tax_field] = False
|
|
247
|
-
tax_methods = [
|
|
248
|
-
self._prepare_fields_issqn,
|
|
249
|
-
self._prepare_fields_csll,
|
|
250
|
-
self._prepare_fields_irpj,
|
|
251
|
-
self._prepare_fields_inss,
|
|
252
|
-
self._prepare_fields_icms,
|
|
253
|
-
self._prepare_fields_icmsfcp,
|
|
254
|
-
self._prepare_fields_icmsfcpst,
|
|
255
|
-
self._prepare_fields_icmsst,
|
|
256
|
-
self._prepare_fields_icmssn,
|
|
257
|
-
self._prepare_fields_ipi,
|
|
258
|
-
self._prepare_fields_ii,
|
|
259
|
-
self._prepare_fields_pis,
|
|
260
|
-
self._prepare_fields_pisst,
|
|
261
|
-
self._prepare_fields_cofins,
|
|
262
|
-
self._prepare_fields_cofinsst,
|
|
263
|
-
self._prepare_fields_issqn_wh,
|
|
264
|
-
self._prepare_fields_pis_wh,
|
|
265
|
-
self._prepare_fields_cofins_wh,
|
|
266
|
-
self._prepare_fields_csll_wh,
|
|
267
|
-
self._prepare_fields_irpj_wh,
|
|
268
|
-
self._prepare_fields_inss_wh,
|
|
269
|
-
]
|
|
270
|
-
for method in tax_methods:
|
|
271
|
-
prepared_fields = method(TAX_DICT_VALUES)
|
|
272
|
-
if prepared_fields:
|
|
273
|
-
to_update.update(prepared_fields)
|
|
274
|
-
# Update all fields at once
|
|
275
|
-
line.update(to_update)
|
|
276
|
-
|
|
277
|
-
def _update_fiscal_tax_ids(self, taxes):
|
|
278
|
-
for line in self:
|
|
279
|
-
taxes_groups = line.fiscal_tax_ids.mapped("tax_domain")
|
|
280
|
-
fiscal_taxes = line.fiscal_tax_ids.filtered(
|
|
281
|
-
lambda ft, taxes_groups=taxes_groups: ft.tax_domain not in taxes_groups
|
|
282
|
-
)
|
|
283
|
-
line.fiscal_tax_ids = fiscal_taxes + taxes
|
|
284
|
-
|
|
285
|
-
def _update_fiscal_taxes(self):
|
|
286
|
-
for line in self:
|
|
287
|
-
compute_result = self._compute_taxes(line.fiscal_tax_ids)
|
|
288
|
-
to_update = {
|
|
289
|
-
"amount_tax_included": compute_result.get("amount_included", 0.0),
|
|
290
|
-
"amount_tax_not_included": compute_result.get(
|
|
291
|
-
"amount_not_included", 0.0
|
|
292
|
-
),
|
|
293
|
-
"amount_tax_withholding": compute_result.get("amount_withholding", 0.0),
|
|
294
|
-
"estimate_tax": compute_result.get("estimate_tax", 0.0),
|
|
295
|
-
}
|
|
296
|
-
to_update.update(line._prepare_tax_fields(compute_result))
|
|
297
|
-
|
|
298
|
-
in_draft_mode = self != self._origin
|
|
299
|
-
if in_draft_mode:
|
|
300
|
-
line.update(to_update)
|
|
301
|
-
else:
|
|
302
|
-
line.write(to_update)
|
|
303
|
-
|
|
304
|
-
def _prepare_tax_fields(self, compute_result):
|
|
305
|
-
self.ensure_one()
|
|
306
|
-
computed_taxes = compute_result.get("taxes", {})
|
|
307
|
-
tax_values = {}
|
|
308
|
-
for tax in self.fiscal_tax_ids:
|
|
309
|
-
computed_tax = computed_taxes.get(tax.tax_domain, {})
|
|
310
|
-
tax_field_name = f"{tax.tax_domain}_tax_id"
|
|
311
|
-
if hasattr(self, tax_field_name):
|
|
312
|
-
tax_values[tax_field_name] = tax.ids[0]
|
|
313
|
-
method = getattr(self, f"_prepare_fields_{tax.tax_domain}", None)
|
|
314
|
-
if method and computed_tax:
|
|
315
|
-
prepared_fields = method(computed_tax)
|
|
316
|
-
if prepared_fields:
|
|
317
|
-
tax_values.update(prepared_fields)
|
|
318
|
-
return tax_values
|
|
319
|
-
|
|
320
|
-
def _get_product_price(self):
|
|
321
|
-
self.ensure_one()
|
|
322
|
-
price = {
|
|
323
|
-
"sale_price": self.product_id.list_price,
|
|
324
|
-
"cost_price": self.product_id.standard_price,
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
self.price_unit = price.get(self.fiscal_operation_id.default_price_unit, 0.00)
|
|
328
|
-
|
|
329
|
-
def __document_comment_vals(self):
|
|
330
|
-
self.ensure_one()
|
|
331
|
-
return {
|
|
332
|
-
"user": self.env.user,
|
|
333
|
-
"ctx": self._context,
|
|
334
|
-
"doc": self.document_id,
|
|
335
|
-
"item": self,
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
def _document_comment(self):
|
|
339
|
-
for d in self:
|
|
340
|
-
d.additional_data = d.comment_ids.compute_message(
|
|
341
|
-
d.__document_comment_vals(), d.manual_additional_data
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
def _get_fiscal_partner(self):
|
|
345
|
-
"""
|
|
346
|
-
Meant to be overriden when the l10n_br_fiscal.document partner_id should not
|
|
347
|
-
be the same as the sale.order, purchase.order, account.move (...) partner_id.
|
|
348
|
-
|
|
349
|
-
(In the case of invoicing, the invoicing partner set by the user should
|
|
350
|
-
get priority over any invoicing contact returned by address_get.)
|
|
351
|
-
"""
|
|
352
|
-
self.ensure_one()
|
|
353
|
-
return self.partner_id
|
|
354
|
-
|
|
355
|
-
@api.onchange("fiscal_operation_id")
|
|
356
|
-
def _onchange_fiscal_operation_id(self):
|
|
357
|
-
if self.fiscal_operation_id:
|
|
358
|
-
if not self.price_unit:
|
|
359
|
-
self._get_product_price()
|
|
360
|
-
self._onchange_commercial_quantity()
|
|
361
|
-
self.fiscal_operation_line_id = self.fiscal_operation_id.line_definition(
|
|
362
|
-
company=self.company_id,
|
|
363
|
-
partner=self._get_fiscal_partner(),
|
|
364
|
-
product=self.product_id,
|
|
365
|
-
)
|
|
366
|
-
self._onchange_fiscal_operation_line_id()
|
|
367
|
-
|
|
368
|
-
@api.onchange("fiscal_operation_line_id")
|
|
369
|
-
def _onchange_fiscal_operation_line_id(self):
|
|
370
|
-
# Reset Taxes
|
|
371
|
-
self._remove_all_fiscal_tax_ids()
|
|
372
|
-
if self.fiscal_operation_line_id:
|
|
373
|
-
mapping_result = self.fiscal_operation_line_id.map_fiscal_taxes(
|
|
374
|
-
company=self.company_id,
|
|
375
|
-
partner=self._get_fiscal_partner(),
|
|
376
|
-
product=self.product_id,
|
|
377
|
-
ncm=self.ncm_id,
|
|
378
|
-
nbm=self.nbm_id,
|
|
379
|
-
nbs=self.nbs_id,
|
|
380
|
-
cest=self.cest_id,
|
|
381
|
-
city_taxation_code=self.city_taxation_code_id,
|
|
382
|
-
service_type=self.service_type_id,
|
|
383
|
-
ind_final=self.ind_final,
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
self.cfop_id = mapping_result["cfop"]
|
|
387
|
-
self._process_fiscal_mapping(mapping_result)
|
|
388
|
-
|
|
389
|
-
if not self.fiscal_operation_line_id:
|
|
390
|
-
self.cfop_id = False
|
|
391
|
-
|
|
392
|
-
def _process_fiscal_mapping(self, mapping_result):
|
|
393
|
-
self.ipi_guideline_id = mapping_result["ipi_guideline"]
|
|
394
|
-
self.icms_tax_benefit_id = mapping_result["icms_tax_benefit_id"]
|
|
395
|
-
taxes = self.env["l10n_br_fiscal.tax"]
|
|
396
|
-
for tax in mapping_result["taxes"].values():
|
|
397
|
-
taxes |= tax
|
|
398
|
-
self.fiscal_tax_ids = taxes
|
|
399
|
-
self._update_fiscal_taxes()
|
|
400
|
-
self.comment_ids = self.fiscal_operation_line_id.comment_ids
|
|
401
|
-
|
|
402
|
-
@api.onchange("product_id")
|
|
403
|
-
def _onchange_product_id_fiscal(self):
|
|
404
|
-
if not self.fiscal_operation_id:
|
|
405
|
-
return
|
|
406
|
-
if self.product_id:
|
|
407
|
-
self.name = self.product_id.display_name
|
|
408
|
-
self.fiscal_type = self.product_id.fiscal_type
|
|
409
|
-
self.uom_id = self.product_id.uom_id
|
|
410
|
-
self.ncm_id = self.product_id.ncm_id
|
|
411
|
-
self.nbm_id = self.product_id.nbm_id
|
|
412
|
-
self.tax_icms_or_issqn = self.product_id.tax_icms_or_issqn
|
|
413
|
-
self.icms_origin = self.product_id.icms_origin
|
|
414
|
-
self.cest_id = self.product_id.cest_id
|
|
415
|
-
self.nbs_id = self.product_id.nbs_id
|
|
416
|
-
self.fiscal_genre_id = self.product_id.fiscal_genre_id
|
|
417
|
-
self.service_type_id = self.product_id.service_type_id
|
|
418
|
-
self.uot_id = self.product_id.uot_id or self.product_id.uom_id
|
|
419
|
-
if self.product_id.city_taxation_code_id:
|
|
420
|
-
company_city_id = self.company_id.city_id
|
|
421
|
-
city_id = self.product_id.city_taxation_code_id.filtered(
|
|
422
|
-
lambda r: r.city_id == company_city_id
|
|
423
|
-
)
|
|
424
|
-
if city_id:
|
|
425
|
-
self.city_taxation_code_id = city_id
|
|
426
|
-
self.issqn_fg_city_id = company_city_id
|
|
427
|
-
else:
|
|
428
|
-
self.name = False
|
|
429
|
-
self.fiscal_type = False
|
|
430
|
-
self.uom_id = False
|
|
431
|
-
self.ncm_id = False
|
|
432
|
-
self.nbm_id = False
|
|
433
|
-
self.tax_icms_or_issqn = False
|
|
434
|
-
self.icms_origin = False
|
|
435
|
-
self.cest_id = False
|
|
436
|
-
self.nbs_id = False
|
|
437
|
-
self.fiscal_genre_id = False
|
|
438
|
-
self.service_type_id = False
|
|
439
|
-
self.city_taxation_code_id = False
|
|
440
|
-
self.uot_id = False
|
|
441
|
-
|
|
442
|
-
self._get_product_price()
|
|
443
|
-
self._onchange_fiscal_operation_id()
|
|
444
|
-
|
|
445
|
-
def _prepare_fields_issqn(self, tax_dict):
|
|
446
|
-
self.ensure_one()
|
|
447
|
-
return {
|
|
448
|
-
"issqn_base": tax_dict.get("base"),
|
|
449
|
-
"issqn_percent": tax_dict.get("percent_amount"),
|
|
450
|
-
"issqn_reduction": tax_dict.get("percent_reduction"),
|
|
451
|
-
"issqn_value": tax_dict.get("tax_value"),
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
@api.onchange("issqn_base", "issqn_percent", "issqn_reduction", "issqn_value")
|
|
455
|
-
def _onchange_issqn_fields(self):
|
|
456
|
-
pass
|
|
457
|
-
|
|
458
|
-
def _prepare_fields_issqn_wh(self, tax_dict):
|
|
459
|
-
self.ensure_one()
|
|
460
|
-
return {
|
|
461
|
-
"issqn_wh_base": tax_dict.get("base"),
|
|
462
|
-
"issqn_wh_percent": tax_dict.get("percent_amount"),
|
|
463
|
-
"issqn_wh_reduction": tax_dict.get("percent_reduction"),
|
|
464
|
-
"issqn_wh_value": tax_dict.get("tax_value"),
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
@api.onchange(
|
|
468
|
-
"issqn_wh_base", "issqn_wh_percent", "issqn_wh_reduction", "issqn_wh_value"
|
|
469
|
-
)
|
|
470
|
-
def _onchange_issqn_wh_fields(self):
|
|
471
|
-
pass
|
|
472
|
-
|
|
473
|
-
def _prepare_fields_csll(self, tax_dict):
|
|
474
|
-
self.ensure_one()
|
|
475
|
-
return {
|
|
476
|
-
"csll_base": tax_dict.get("base"),
|
|
477
|
-
"csll_percent": tax_dict.get("percent_amount"),
|
|
478
|
-
"csll_reduction": tax_dict.get("percent_reduction"),
|
|
479
|
-
"csll_value": tax_dict.get("tax_value"),
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
@api.onchange("csll_base", "csll_percent", "csll_reduction", "csll_value")
|
|
483
|
-
def _onchange_csll_fields(self):
|
|
484
|
-
pass
|
|
485
|
-
|
|
486
|
-
def _prepare_fields_csll_wh(self, tax_dict):
|
|
487
|
-
self.ensure_one()
|
|
488
|
-
return {
|
|
489
|
-
"csll_wh_base": tax_dict.get("base"),
|
|
490
|
-
"csll_wh_percent": tax_dict.get("percent_amount"),
|
|
491
|
-
"csll_wh_reduction": tax_dict.get("percent_reduction"),
|
|
492
|
-
"csll_wh_value": tax_dict.get("tax_value"),
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
@api.onchange(
|
|
496
|
-
"csll_wh_base", "csll_wh_percent", "csll_wh_reduction", "csll_wh_value"
|
|
497
|
-
)
|
|
498
|
-
def _onchange_csll_wh_fields(self):
|
|
499
|
-
pass
|
|
500
|
-
|
|
501
|
-
def _prepare_fields_irpj(self, tax_dict):
|
|
502
|
-
self.ensure_one()
|
|
503
|
-
return {
|
|
504
|
-
"irpj_base": tax_dict.get("base"),
|
|
505
|
-
"irpj_percent": tax_dict.get("percent_amount"),
|
|
506
|
-
"irpj_reduction": tax_dict.get("percent_reduction"),
|
|
507
|
-
"irpj_value": tax_dict.get("tax_value"),
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
@api.onchange("irpj_base", "irpj_percent", "irpj_reduction", "irpj_value")
|
|
511
|
-
def _onchange_irpj_fields(self):
|
|
512
|
-
pass
|
|
513
|
-
|
|
514
|
-
def _prepare_fields_irpj_wh(self, tax_dict):
|
|
515
|
-
self.ensure_one()
|
|
516
|
-
return {
|
|
517
|
-
"irpj_wh_base": tax_dict.get("base"),
|
|
518
|
-
"irpj_wh_percent": tax_dict.get("percent_amount"),
|
|
519
|
-
"irpj_wh_reduction": tax_dict.get("percent_reduction"),
|
|
520
|
-
"irpj_wh_value": tax_dict.get("tax_value"),
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
@api.onchange(
|
|
524
|
-
"irpj_wh_base", "irpj_wh_percent", "irpj_wh_reduction", "irpj_wh_value"
|
|
525
|
-
)
|
|
526
|
-
def _onchange_irpj_wh_fields(self):
|
|
527
|
-
pass
|
|
528
|
-
|
|
529
|
-
def _prepare_fields_inss(self, tax_dict):
|
|
530
|
-
self.ensure_one()
|
|
531
|
-
return {
|
|
532
|
-
"inss_base": tax_dict.get("base"),
|
|
533
|
-
"inss_percent": tax_dict.get("percent_amount"),
|
|
534
|
-
"inss_reduction": tax_dict.get("percent_reduction"),
|
|
535
|
-
"inss_value": tax_dict.get("tax_value"),
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
@api.onchange("inss_base", "inss_percent", "inss_reduction", "inss_value")
|
|
539
|
-
def _onchange_inss_fields(self):
|
|
540
|
-
pass
|
|
541
|
-
|
|
542
|
-
def _prepare_fields_inss_wh(self, tax_dict):
|
|
543
|
-
self.ensure_one()
|
|
544
|
-
return {
|
|
545
|
-
"inss_wh_base": tax_dict.get("base"),
|
|
546
|
-
"inss_wh_percent": tax_dict.get("percent_amount"),
|
|
547
|
-
"inss_wh_reduction": tax_dict.get("percent_reduction"),
|
|
548
|
-
"inss_wh_value": tax_dict.get("tax_value"),
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
@api.onchange(
|
|
552
|
-
"inss_wh_base", "inss_wh_percent", "inss_wh_reduction", "inss_wh_value"
|
|
553
|
-
)
|
|
554
|
-
def _onchange_inss_wh_fields(self):
|
|
555
|
-
pass
|
|
556
|
-
|
|
557
|
-
def _prepare_fields_icms(self, tax_dict):
|
|
558
|
-
self.ensure_one()
|
|
559
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
560
|
-
return {
|
|
561
|
-
"icms_cst_id": cst_id,
|
|
562
|
-
"icms_base_type": tax_dict.get("icms_base_type", ICMS_BASE_TYPE_DEFAULT),
|
|
563
|
-
"icms_base": tax_dict.get("base", 0.0),
|
|
564
|
-
"icms_percent": tax_dict.get("percent_amount", 0.0),
|
|
565
|
-
"icms_reduction": tax_dict.get("percent_reduction", 0.0),
|
|
566
|
-
"icms_value": tax_dict.get("tax_value", 0.0),
|
|
567
|
-
"icms_origin_percent": tax_dict.get("icms_origin_perc", 0.0),
|
|
568
|
-
"icms_destination_percent": tax_dict.get("icms_dest_perc", 0.0),
|
|
569
|
-
"icms_sharing_percent": tax_dict.get("icms_sharing_percent", 0.0),
|
|
570
|
-
"icms_destination_base": tax_dict.get("icms_dest_base", 0.0),
|
|
571
|
-
"icms_origin_value": tax_dict.get("icms_origin_value", 0.0),
|
|
572
|
-
"icms_destination_value": tax_dict.get("icms_dest_value", 0.0),
|
|
573
|
-
"icms_relief_value": tax_dict.get("icms_relief", 0.0),
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
@api.onchange(
|
|
577
|
-
"icms_base",
|
|
578
|
-
"icms_percent",
|
|
579
|
-
"icms_reduction",
|
|
580
|
-
"icms_value",
|
|
581
|
-
"icms_destination_base",
|
|
582
|
-
"icms_origin_percent",
|
|
583
|
-
"icms_destination_percent",
|
|
584
|
-
"icms_sharing_percent",
|
|
585
|
-
"icms_origin_value",
|
|
586
|
-
"icms_tax_benefit_id",
|
|
587
|
-
)
|
|
588
|
-
def _onchange_icms_fields(self):
|
|
589
|
-
if self.icms_tax_benefit_id:
|
|
590
|
-
self.icms_tax_id = self.icms_tax_benefit_id.tax_id
|
|
591
|
-
|
|
592
|
-
def _prepare_fields_icmssn(self, tax_dict):
|
|
593
|
-
self.ensure_one()
|
|
594
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
595
|
-
icmssn_base = tax_dict.get("base", 0.0)
|
|
596
|
-
icmssn_credit_value = tax_dict.get("tax_value", 0.0)
|
|
597
|
-
simple_value = icmssn_base * self.icmssn_range_id.total_tax_percent
|
|
598
|
-
simple_without_icms_value = simple_value - icmssn_credit_value
|
|
599
|
-
return {
|
|
600
|
-
"icms_cst_id": cst_id,
|
|
601
|
-
"icmssn_base": icmssn_base,
|
|
602
|
-
"icmssn_percent": tax_dict.get("percent_amount"),
|
|
603
|
-
"icmssn_reduction": tax_dict.get("percent_reduction"),
|
|
604
|
-
"icmssn_credit_value": icmssn_credit_value,
|
|
605
|
-
"simple_value": simple_value,
|
|
606
|
-
"simple_without_icms_value": simple_without_icms_value,
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
@api.onchange(
|
|
610
|
-
"icmssn_base", "icmssn_percent", "icmssn_reduction", "icmssn_credit_value"
|
|
611
|
-
)
|
|
612
|
-
def _onchange_icmssn_fields(self):
|
|
613
|
-
pass
|
|
614
|
-
|
|
615
|
-
def _prepare_fields_icmsst(self, tax_dict):
|
|
616
|
-
self.ensure_one()
|
|
617
|
-
return {
|
|
618
|
-
"icmsst_base_type": tax_dict.get(
|
|
619
|
-
"icmsst_base_type", ICMS_ST_BASE_TYPE_DEFAULT
|
|
620
|
-
),
|
|
621
|
-
"icmsst_mva_percent": tax_dict.get("icmsst_mva_percent"),
|
|
622
|
-
"icmsst_percent": tax_dict.get("percent_amount"),
|
|
623
|
-
"icmsst_reduction": tax_dict.get("percent_reduction"),
|
|
624
|
-
"icmsst_base": tax_dict.get("base"),
|
|
625
|
-
"icmsst_value": tax_dict.get("tax_value"),
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
@api.onchange(
|
|
629
|
-
"icmsst_base_type",
|
|
630
|
-
"icmsst_mva_percent",
|
|
631
|
-
"icmsst_percent",
|
|
632
|
-
"icmsst_reduction",
|
|
633
|
-
"icmsst_base",
|
|
634
|
-
"icmsst_value",
|
|
635
|
-
"icmsst_wh_base",
|
|
636
|
-
"icmsst_wh_value",
|
|
637
|
-
)
|
|
638
|
-
def _onchange_icmsst_fields(self):
|
|
639
|
-
pass
|
|
640
|
-
|
|
641
|
-
def _prepare_fields_icmsfcp(self, tax_dict):
|
|
642
|
-
self.ensure_one()
|
|
643
|
-
return {
|
|
644
|
-
"icmsfcp_base": tax_dict.get("base", 0.0),
|
|
645
|
-
"icmsfcp_percent": tax_dict.get("percent_amount", 0.0),
|
|
646
|
-
"icmsfcp_value": tax_dict.get("tax_value", 0.0),
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
def _prepare_fields_icmsfcpst(self, tax_dict):
|
|
650
|
-
self.ensure_one()
|
|
651
|
-
return {
|
|
652
|
-
"icmsfcpst_base": self.icmsst_base,
|
|
653
|
-
"icmsfcpst_percent": tax_dict.get("percent_amount", 0.0),
|
|
654
|
-
"icmsfcpst_value": tax_dict.get("tax_value", 0.0),
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
@api.onchange("icmsfcp_percent", "icmsfcp_value")
|
|
658
|
-
def _onchange_icmsfcp_fields(self):
|
|
659
|
-
pass
|
|
660
|
-
|
|
661
|
-
def _prepare_fields_ipi(self, tax_dict):
|
|
662
|
-
self.ensure_one()
|
|
663
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
664
|
-
return {
|
|
665
|
-
"ipi_cst_id": cst_id,
|
|
666
|
-
"ipi_base_type": tax_dict.get("base_type", False),
|
|
667
|
-
"ipi_base": tax_dict.get("base", 0.00),
|
|
668
|
-
"ipi_percent": tax_dict.get("percent_amount", 0.00),
|
|
669
|
-
"ipi_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
670
|
-
"ipi_value": tax_dict.get("tax_value", 0.00),
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
@api.onchange("ipi_base", "ipi_percent", "ipi_reduction", "ipi_value")
|
|
674
|
-
def _onchange_ipi_fields(self):
|
|
675
|
-
pass
|
|
676
|
-
|
|
677
|
-
def _prepare_fields_ii(self, tax_dict):
|
|
678
|
-
self.ensure_one()
|
|
679
|
-
return {
|
|
680
|
-
"ii_base": tax_dict.get("base", 0.00),
|
|
681
|
-
"ii_percent": tax_dict.get("percent_amount", 0.00),
|
|
682
|
-
"ii_value": tax_dict.get("tax_value", 0.00),
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
@api.onchange("ii_base", "ii_percent", "ii_value")
|
|
686
|
-
def _onchange_ii_fields(self):
|
|
687
|
-
pass
|
|
688
|
-
|
|
689
|
-
def _prepare_fields_pis(self, tax_dict):
|
|
690
|
-
self.ensure_one()
|
|
691
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
692
|
-
return {
|
|
693
|
-
"pis_cst_id": cst_id,
|
|
694
|
-
"pis_base_type": tax_dict.get("base_type"),
|
|
695
|
-
"pis_base": tax_dict.get("base", 0.00),
|
|
696
|
-
"pis_percent": tax_dict.get("percent_amount", 0.00),
|
|
697
|
-
"pis_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
698
|
-
"pis_value": tax_dict.get("tax_value", 0.00),
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
@api.onchange(
|
|
702
|
-
"pis_base_type", "pis_base", "pis_percent", "pis_reduction", "pis_value"
|
|
703
|
-
)
|
|
704
|
-
def _onchange_pis_fields(self):
|
|
705
|
-
pass
|
|
706
|
-
|
|
707
|
-
def _prepare_fields_pis_wh(self, tax_dict):
|
|
708
|
-
self.ensure_one()
|
|
709
|
-
return {
|
|
710
|
-
"pis_wh_base_type": tax_dict.get("base_type"),
|
|
711
|
-
"pis_wh_base": tax_dict.get("base", 0.00),
|
|
712
|
-
"pis_wh_percent": tax_dict.get("percent_amount", 0.00),
|
|
713
|
-
"pis_wh_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
714
|
-
"pis_wh_value": tax_dict.get("tax_value", 0.00),
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
@api.onchange(
|
|
718
|
-
"pis_wh_base_type",
|
|
719
|
-
"pis_wh_base",
|
|
720
|
-
"pis_wh_percent",
|
|
721
|
-
"pis_wh_reduction",
|
|
722
|
-
"pis_wh_value",
|
|
723
|
-
)
|
|
724
|
-
def _onchange_pis_wh_fields(self):
|
|
725
|
-
pass
|
|
726
|
-
|
|
727
|
-
def _prepare_fields_pisst(self, tax_dict):
|
|
728
|
-
self.ensure_one()
|
|
729
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
730
|
-
return {
|
|
731
|
-
"pisst_cst_id": cst_id,
|
|
732
|
-
"pisst_base_type": tax_dict.get("base_type"),
|
|
733
|
-
"pisst_base": tax_dict.get("base", 0.00),
|
|
734
|
-
"pisst_percent": tax_dict.get("percent_amount", 0.00),
|
|
735
|
-
"pisst_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
736
|
-
"pisst_value": tax_dict.get("tax_value", 0.00),
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
@api.onchange(
|
|
740
|
-
"pisst_base_type",
|
|
741
|
-
"pisst_base",
|
|
742
|
-
"pisst_percent",
|
|
743
|
-
"pisst_reduction",
|
|
744
|
-
"pisst_value",
|
|
745
|
-
)
|
|
746
|
-
def _onchange_pisst_fields(self):
|
|
747
|
-
pass
|
|
748
|
-
|
|
749
|
-
def _prepare_fields_cofins(self, tax_dict):
|
|
750
|
-
self.ensure_one()
|
|
751
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
752
|
-
return {
|
|
753
|
-
"cofins_cst_id": cst_id,
|
|
754
|
-
"cofins_base_type": tax_dict.get("base_type"),
|
|
755
|
-
"cofins_base": tax_dict.get("base", 0.00),
|
|
756
|
-
"cofins_percent": tax_dict.get("percent_amount", 0.00),
|
|
757
|
-
"cofins_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
758
|
-
"cofins_value": tax_dict.get("tax_value", 0.00),
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
@api.onchange(
|
|
762
|
-
"cofins_base_type",
|
|
763
|
-
"cofins_base",
|
|
764
|
-
"cofins_percent",
|
|
765
|
-
"cofins_reduction",
|
|
766
|
-
"cofins_value",
|
|
767
|
-
)
|
|
768
|
-
def _onchange_cofins_fields(self):
|
|
769
|
-
pass
|
|
770
|
-
|
|
771
|
-
def _prepare_fields_cofins_wh(self, tax_dict):
|
|
772
|
-
self.ensure_one()
|
|
773
|
-
return {
|
|
774
|
-
"cofins_wh_base_type": tax_dict.get("base_type"),
|
|
775
|
-
"cofins_wh_base": tax_dict.get("base", 0.00),
|
|
776
|
-
"cofins_wh_percent": tax_dict.get("percent_amount", 0.00),
|
|
777
|
-
"cofins_wh_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
778
|
-
"cofins_wh_value": tax_dict.get("tax_value", 0.00),
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
@api.onchange(
|
|
782
|
-
"cofins_wh_base_type",
|
|
783
|
-
"cofins_wh_base",
|
|
784
|
-
"cofins_wh_percent",
|
|
785
|
-
"cofins_wh_reduction",
|
|
786
|
-
"cofins_wh_value",
|
|
787
|
-
)
|
|
788
|
-
def _onchange_cofins_wh_fields(self):
|
|
789
|
-
pass
|
|
790
|
-
|
|
791
|
-
def _prepare_fields_cofinsst(self, tax_dict):
|
|
792
|
-
self.ensure_one()
|
|
793
|
-
cst_id = tax_dict.get("cst_id").id if tax_dict.get("cst_id") else False
|
|
794
|
-
return {
|
|
795
|
-
"cofinsst_cst_id": cst_id,
|
|
796
|
-
"cofinsst_base_type": tax_dict.get("base_type"),
|
|
797
|
-
"cofinsst_base": tax_dict.get("base", 0.00),
|
|
798
|
-
"cofinsst_percent": tax_dict.get("percent_amount", 0.00),
|
|
799
|
-
"cofinsst_reduction": tax_dict.get("percent_reduction", 0.00),
|
|
800
|
-
"cofinsst_value": tax_dict.get("tax_value", 0.00),
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
@api.onchange(
|
|
804
|
-
"cofinsst_base_type",
|
|
805
|
-
"cofinsst_base",
|
|
806
|
-
"cofinsst_percent",
|
|
807
|
-
"cofinsst_reduction",
|
|
808
|
-
"cofinsst_value",
|
|
809
|
-
)
|
|
810
|
-
def _onchange_cofinsst_fields(self):
|
|
811
|
-
pass
|
|
812
|
-
|
|
813
|
-
@api.onchange(
|
|
814
|
-
"csll_tax_id",
|
|
815
|
-
"csll_wh_tax_id",
|
|
816
|
-
"irpj_tax_id",
|
|
817
|
-
"irpj_wh_tax_id",
|
|
818
|
-
"inss_tax_id",
|
|
819
|
-
"inss_wh_tax_id",
|
|
820
|
-
"issqn_tax_id",
|
|
821
|
-
"issqn_wh_tax_id",
|
|
822
|
-
"icms_tax_id",
|
|
823
|
-
"icmssn_tax_id",
|
|
824
|
-
"icmsst_tax_id",
|
|
825
|
-
"icmsfcp_tax_id",
|
|
826
|
-
"icmsfcpst_tax_id",
|
|
827
|
-
"icms_relief_id",
|
|
828
|
-
"icms_relief_value",
|
|
829
|
-
"ipi_tax_id",
|
|
830
|
-
"ii_tax_id",
|
|
831
|
-
"pis_tax_id",
|
|
832
|
-
"pis_wh_tax_id",
|
|
833
|
-
"pisst_tax_id",
|
|
834
|
-
"cofins_tax_id",
|
|
835
|
-
"cofins_wh_tax_id",
|
|
836
|
-
"cofinsst_tax_id",
|
|
837
|
-
"fiscal_price",
|
|
838
|
-
"fiscal_quantity",
|
|
839
|
-
"discount_value",
|
|
840
|
-
"insurance_value",
|
|
841
|
-
"other_value",
|
|
842
|
-
"freight_value",
|
|
843
|
-
)
|
|
844
|
-
def _onchange_fiscal_taxes(self):
|
|
845
|
-
self._update_fiscal_tax_ids(self._get_all_tax_id_fields())
|
|
846
|
-
self._update_fiscal_taxes()
|
|
847
|
-
|
|
848
|
-
@api.model
|
|
849
|
-
def _update_fiscal_quantity(self, product_id, price, quantity, uom_id, uot_id):
|
|
850
|
-
result = {"uot_id": uom_id, "fiscal_quantity": quantity, "fiscal_price": price}
|
|
851
|
-
if uot_id and uom_id != uot_id:
|
|
852
|
-
result["uot_id"] = uot_id
|
|
853
|
-
if product_id and price and quantity:
|
|
854
|
-
product = self.env["product.product"].browse(product_id)
|
|
855
|
-
result["fiscal_price"] = price / (product.uot_factor or 1.0)
|
|
856
|
-
result["fiscal_quantity"] = quantity * (product.uot_factor or 1.0)
|
|
857
|
-
|
|
858
|
-
return result
|
|
859
|
-
|
|
860
|
-
@api.onchange("uot_id", "uom_id", "price_unit", "quantity")
|
|
861
|
-
def _onchange_commercial_quantity(self):
|
|
862
|
-
product_id = False
|
|
863
|
-
if self.product_id:
|
|
864
|
-
product_id = self.product_id.id
|
|
865
|
-
self.update(
|
|
866
|
-
self._update_fiscal_quantity(
|
|
867
|
-
product_id, self.price_unit, self.quantity, self.uom_id, self.uot_id
|
|
868
|
-
)
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
@api.onchange("ii_customhouse_charges")
|
|
872
|
-
def _onchange_ii_customhouse_charges(self):
|
|
873
|
-
if self.ii_customhouse_charges:
|
|
874
|
-
self._update_fiscal_taxes()
|
|
875
|
-
|
|
876
|
-
@api.onchange("ncm_id", "nbs_id", "cest_id")
|
|
877
|
-
def _onchange_ncm_id(self):
|
|
878
|
-
self._onchange_fiscal_operation_id()
|
|
879
|
-
|
|
880
|
-
@api.onchange("fiscal_tax_ids")
|
|
881
|
-
def _onchange_fiscal_tax_ids(self):
|
|
882
|
-
self._update_fiscal_taxes()
|
|
883
|
-
|
|
884
|
-
@api.onchange("city_taxation_code_id")
|
|
885
|
-
def _onchange_city_taxation_code_id(self):
|
|
886
|
-
if self.city_taxation_code_id:
|
|
887
|
-
self.cnae_id = self.city_taxation_code_id.cnae_id
|
|
888
|
-
self._onchange_fiscal_operation_id()
|
|
889
|
-
if self.city_taxation_code_id.city_id:
|
|
890
|
-
self.update({"issqn_fg_city_id": self.city_taxation_code_id.city_id})
|
|
891
|
-
|
|
892
|
-
@api.onchange("service_type_id")
|
|
893
|
-
def _onchange_service_type_id(self):
|
|
894
|
-
if self.service_type_id:
|
|
895
|
-
self._onchange_fiscal_operation_id()
|
|
896
|
-
|
|
897
|
-
@api.model
|
|
898
|
-
def _add_fields_to_amount(self):
|
|
899
|
-
fields_to_amount = ["insurance_value", "other_value", "freight_value"]
|
|
900
|
-
if (
|
|
901
|
-
self.cfop_id.destination == CFOP_DESTINATION_EXPORT
|
|
902
|
-
and self.fiscal_operation_id.fiscal_operation_type == FISCAL_IN
|
|
903
|
-
):
|
|
904
|
-
fields_to_amount.append("pis_value")
|
|
905
|
-
fields_to_amount.append("cofins_value")
|
|
906
|
-
fields_to_amount.append("icms_value")
|
|
907
|
-
fields_to_amount.append("ii_value")
|
|
908
|
-
fields_to_amount.append("ii_customhouse_charges")
|
|
909
|
-
return fields_to_amount
|
|
910
|
-
|
|
911
|
-
@api.model
|
|
912
|
-
def _rm_fields_to_amount(self):
|
|
913
|
-
return ["icms_relief_value"]
|