-
-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][IMP] l10n_br_fiscal: add icms difal regulation #2501
Open
felipemotter
wants to merge
1
commit into
OCA:14.0
Choose a base branch
from
Engenere:14.0-difal-regulation
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
l10n_br_fiscal/data/l10n_br_fiscal_icms_difal_definition_data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="True"> | ||
<record id="tax_icms_difal_regulation" model="l10n_br_fiscal.icms.difal.regulation"> | ||
<field name="name">Regulamento do ICMS Difal</field> | ||
<field | ||
name="unique_base_state_ids" | ||
eval="[(6, 0, [ | ||
ref('base.state_br_ac'), | ||
ref('base.state_br_al'), | ||
ref('base.state_br_am'), | ||
ref('base.state_br_ap'), | ||
ref('base.state_br_ba'), | ||
ref('base.state_br_ce'), | ||
ref('base.state_br_df'), | ||
ref('base.state_br_es'), | ||
ref('base.state_br_go'), | ||
ref('base.state_br_ma'), | ||
ref('base.state_br_mg'), | ||
ref('base.state_br_ms'), | ||
ref('base.state_br_mt'), | ||
ref('base.state_br_pa'), | ||
ref('base.state_br_pb'), | ||
ref('base.state_br_pe'), | ||
ref('base.state_br_pi'), | ||
ref('base.state_br_pr'), | ||
ref('base.state_br_rj'), | ||
ref('base.state_br_rn'), | ||
ref('base.state_br_ro'), | ||
ref('base.state_br_rr'), | ||
ref('base.state_br_rs'), | ||
ref('base.state_br_sc'), | ||
ref('base.state_br_se'), | ||
ref('base.state_br_sp'), | ||
ref('base.state_br_to') | ||
])]" | ||
/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (C) 2023 Felipe Motter Pereira - Akretion <[email protected]> | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ICMSDifalRegulation(models.Model): | ||
_name = "l10n_br_fiscal.icms.difal.regulation" | ||
_description = "ICMS Difal Regulation" | ||
|
||
name = fields.Text(required=True, index=True) | ||
|
||
unique_base_state_ids = fields.Many2many( | ||
comodel_name="res.country.state", | ||
relation="icms_difal_regulation_unique_base_state_rel", | ||
column1="icms_difal_regulation", | ||
column2="state_id", | ||
string="States with Unique Base", | ||
domain=[("country_id.code", "=", "BR")], | ||
) | ||
|
||
double_base_state_ids = fields.Many2many( | ||
comodel_name="res.country.state", | ||
relation="icms_difal_regulation_double_base_state_rel", | ||
column1="icms_difal_regulation", | ||
column2="state_id", | ||
string="States with Double Base", | ||
domain=[("country_id.code", "=", "BR")], | ||
) | ||
|
||
@api.constrains("unique_base_state_ids", "double_base_state_ids") | ||
def _check_duplicity(self): | ||
for state in self.unique_base_state_ids: | ||
if state in self.double_base_state_ids: | ||
raise UserError(_("You cannot have two bases for same state.")) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright 2020 Akretion - Renato Lima <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import exceptions | ||
from odoo.tests import SavepointCase | ||
from odoo.tools import float_compare | ||
|
||
|
@@ -303,3 +304,45 @@ def test_compute_taxes_03(self): | |
} | ||
|
||
self._check_compute_taxes_result(test_result, compute_result, currency) | ||
|
||
def test_difal(self): | ||
"""Testa o calculo dos impostos de compra - entrada de importação""" | ||
|
||
kwargs = self._create_compute_taxes_kwargs() | ||
currency = kwargs["company"].currency_id | ||
|
||
kwargs["partner"] = self.env.ref("l10n_br_base.res_partner_cliente10_mg") | ||
|
||
fiscal_taxes = self.env["l10n_br_fiscal.tax"] | ||
fiscal_taxes |= self.env.ref("l10n_br_fiscal.tax_icms_4") | ||
|
||
difal_regulation = self.env.ref("l10n_br_fiscal.tax_icms_difal_regulation") | ||
kwargs["company"].icms_difal_regulation_id = False | ||
|
||
with self.assertRaises(exceptions.UserError): | ||
fiscal_taxes.compute_taxes(**kwargs) | ||
|
||
kwargs["company"].icms_difal_regulation_id = difal_regulation | ||
|
||
compute_result = fiscal_taxes.compute_taxes(**kwargs) | ||
|
||
test_result = { | ||
"amount_included": 1.38, | ||
"amount_not_included": 0.0, | ||
"amount_withholding": 0.0, | ||
"estimate_tax": 0.0, | ||
"taxes": { | ||
"icms": { | ||
"icms_dest_base": 34.58, | ||
"icms_dest_value": 4.84, | ||
}, | ||
}, | ||
} | ||
|
||
self._check_compute_taxes_result(test_result, compute_result, currency) | ||
|
||
difal_regulation.unique_base_state_ids = [(5, 0, 0)] | ||
difal_regulation.double_base_state_ids = [(5, 0, 0)] | ||
|
||
with self.assertRaises(exceptions.UserError): | ||
fiscal_taxes.compute_taxes(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright 2019 Akretion - Renato Lima <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import UserError | ||
from odoo.tests import SavepointCase, tagged | ||
|
||
from ..constants.fiscal import FINAL_CUSTOMER_NO, FINAL_CUSTOMER_YES, TAX_DOMAIN_ICMS | ||
|
@@ -75,3 +76,16 @@ def find_icms_tax(self, in_state_id, out_state_id, ncm_id, ind_final): | |
ind_final=ind_final, | ||
) | ||
return tax_icms.filtered(lambda t: t.tax_domain == TAX_DOMAIN_ICMS) | ||
|
||
def test_state_difal_base_duplicity(self): | ||
|
||
demo_state = self.env.ref("base.state_br_sc") | ||
|
||
with self.assertRaises(UserError): | ||
self.env["l10n_br_fiscal.icms.difal.regulation"].create( | ||
{ | ||
"name": "Difal Test", | ||
"unique_base_state_ids": [(4, demo_state.id, 0)], | ||
"double_base_state_ids": [(4, demo_state.id, 0)], | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mileo você diz por um default aqui certo ?
cc @felipemotter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pode ser ai ou nos dados, mas fiquei um pouco na dúvida de como icms_regulation_id da empresa principal esta sendo preenchida.
Se for possível, quanto menos dados forem necessários para configurar uma empresa para operar melhor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felipemotter @antoniospneto alguns dias atrás atualizando uma base no meu ambiente dev (com esta PR) deu erro devido a falta de valor em icms_difal_regulation_id no modelo res.company.
Infelizmente não printei mas acho que pode ser que tenha chamado o _compute_icms e caiu no teste da linha 425