Skip to content
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: Melhoria no funcionamento dos impostos estimados #3373

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_br_fiscal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"maintainers": ["renatonlima"],
"website": "https://github.com/OCA/l10n-brazil",
"development_status": "Production/Stable",
"version": "14.0.23.3.1",
"version": "14.0.24.0.0",
"depends": [
"product",
"l10n_br_base",
Expand Down
7 changes: 7 additions & 0 deletions l10n_br_fiscal/data/ibpt_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="config_param_ibpt_request_timeout" model="ir.config_parameter">
<field name="key">ibpt_request_timeout</field>
<field name="value">299</field>
</record>
</odoo>
8 changes: 8 additions & 0 deletions l10n_br_fiscal/migrations/14.0.24.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.delete_records_safely_by_xml_id(
env, ["l10n_br_fiscal.l10n_br_fiscal_tax_estimate_rule"]
)
63 changes: 24 additions & 39 deletions l10n_br_fiscal/models/data_ncm_nbs_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,32 @@ class DataNcmNbsAbstract(models.AbstractModel):
readonly=True,
)

estimate_tax_national = fields.Float(
string="Estimate Tax Nacional Percent",
store=True,
readonly=True,
digits="Fiscal Tax Percent",
compute="_compute_amount",
)

estimate_tax_imported = fields.Float(
string="Estimate Tax Imported Percent",
store=True,
readonly=True,
digits="Fiscal Tax Percent",
compute="_compute_amount",
)
def get_estimated_taxes(self):
self.ensure_one()
object_field = OBJECT_FIELDS.get(self._name)
last_estimated = self.env["l10n_br_fiscal.tax.estimate"].search(
[
(object_field, "=", self.id),
("state_id", "=", self.env.company.state_id.id),
],
order="create_date DESC",
limit=1,
)
Comment on lines +34 to +44
Copy link
Contributor

@antoniospneto antoniospneto Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui eu ainda não consegui compreender qual vantagem de trocar compute por esse método..
Tem que ver se isso é o que o @renatonlima queria, talvez não era bem isso..

Eu penso que talvez não é o mais seguro buscar o estado de dentro da empresa ativa.
Acho que seria melhor o local que precisar dessa informação informar o estado, por exemplo na Fatura, seria pego o estado de dentro do company_id definido na fatura.


@api.depends("tax_estimate_ids")
def _compute_amount(self):
for record in self:
object_field = OBJECT_FIELDS.get(record._name)
last_estimated = record.env["l10n_br_fiscal.tax.estimate"].search(
[
(object_field, "=", record.id),
("company_id", "=", record.env.company.id),
],
order="create_date DESC",
limit=1,
if last_estimated:
estimate_tax_imported = (
last_estimated.federal_taxes_import
+ last_estimated.state_taxes
+ last_estimated.municipal_taxes
)

if last_estimated:
record.estimate_tax_imported = (
last_estimated.federal_taxes_import
+ last_estimated.state_taxes
+ last_estimated.municipal_taxes
)

record.estimate_tax_national = (
last_estimated.federal_taxes_national
+ last_estimated.state_taxes
+ last_estimated.municipal_taxes
)
estimate_tax_national = (
last_estimated.federal_taxes_national
+ last_estimated.state_taxes
+ last_estimated.municipal_taxes
)
return estimate_tax_national, estimate_tax_imported
else:
return 0, 0

def _get_ibpt(self, config, code_unmasked):
return False
Expand Down
8 changes: 5 additions & 3 deletions l10n_br_fiscal/models/tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,19 @@ def _compute_estimate_taxes(self, **kwargs):
and op_line.fiscal_operation_id.fiscal_type == "sale"
):
if nbs:
estimate_tax_national, estimate_tax_imported = nbs.get_estimated_taxes()
amount_estimate_tax = currency.round(
amount_total * (nbs.estimate_tax_national / 100)
amount_total * (estimate_tax_national / 100)
)
elif ncm:
estimate_tax_national, estimate_tax_imported = ncm.get_estimated_taxes()
if icms_origin in ICMS_ORIGIN_TAX_IMPORTED:
amount_estimate_tax = currency.round(
amount_total * (ncm.estimate_tax_imported / 100)
amount_total * (estimate_tax_imported / 100)
)
else:
amount_estimate_tax = currency.round(
amount_total * (ncm.estimate_tax_national / 100)
amount_total * (estimate_tax_national / 100)
)

return amount_estimate_tax
Expand Down
26 changes: 20 additions & 6 deletions l10n_br_fiscal/models/tax_estimate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2012 Renato Lima - Akretion <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
from odoo import api, fields, models


class TaxEstimate(models.Model):
Expand Down Expand Up @@ -43,8 +43,22 @@ class TaxEstimate(models.Model):

origin = fields.Char(string="Source", size=32)

company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda self: self.env.company,
)
active = fields.Boolean(string="Ativo", default=True)

def _deactivate_old_estimates(self):
for estimate in self:
domain = [
("id", "!=", estimate.id),
("state_id", "=", estimate.state_id.id),
"|",
("ncm_id", "=", estimate.ncm_id.id),
("nbs_id", "=", estimate.nbs_id.id),
]
old_estimates = self.search(domain)
old_estimates.write({"active": False})

@api.model_create_multi
def create(self, vals_list):
estimates = super().create(vals_list)
estimates._deactivate_old_estimates()
return estimates
Comment on lines +46 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O que motivou a criar esse campo de ativo? não vejo muita necessidade nisso.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vi que isso foi proposto pelo @renatonlima aqui:
#3152 (comment)

Mas tem que ver melhor, da forma que tá sendo feito não tá fazendo diferença..

Copy link
Contributor

@antoniospneto antoniospneto Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pessoal, o que eu acho que dá pra fazer, é manter apenas uma linha de imposto estimado para cada estado no NCM/NBS. não acho necessário fazer um controle de ativo ou desativo. Nem é interessante manter um histórico das taxas antigas, isso só geraria muito lixo no banco de dados, só de NCM temos 40 mil linhas.. pensa no quanto isso pode crescer.

Poderia até fazer uma validação para não permitir dois impostos aproximados para o mesmo Estado, mesmo NCM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

talvez já daria para manter o histórico das mudanças no chatter apenas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acho que por a data de sincronização na linha do imposto estimado já seria o bastante, se não o chatter vai ficar monstruoso tbm, a configuração padrão é atualizar a cada 15 dias, acho que vai ser muito spam, opnião minha.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concordo no módulo l10n_br_fiscal é melhor assim mesmo. Tem como logar isso num módulo extra se alguém quiser. Num projeto eu sobrecarreguei a logica do chatter para conservar apenas os ultimos N mensagens. Mas melhor guardar isso para um modulo extra do que acumular muito mais coisas nesse módulo.

4 changes: 1 addition & 3 deletions l10n_br_fiscal/security/fiscal_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
<field name="name">Fiscal Tax Estimate multi-company</field>
<field name="model_id" ref="model_l10n_br_fiscal_tax_estimate" />
<field eval="True" name="global" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
<field name="domain_force">[]</field>
</record>

<record id="l10n_br_fiscal_operation_line_rule" model="ir.rule">
Expand Down
8 changes: 0 additions & 8 deletions l10n_br_fiscal/views/nbs_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@
<field name="product_tmpl_ids" />
</page>
<page string="Estimate Taxes" name="tax_estimate">
<group>
<group>
<field name="estimate_tax_national" />
</group>
<group>
<field name="estimate_tax_imported" />
</group>
</group>
<field name="tax_estimate_ids" />
</page>
</notebook>
Expand Down
8 changes: 0 additions & 8 deletions l10n_br_fiscal/views/ncm_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@
<field name="piscofins_ids" />
</page>
<page string="Estimate Taxes" name="tax_estimate">
<group>
<group>
<field name="estimate_tax_national" />
</group>
<group>
<field name="estimate_tax_imported" />
</group>
</group>
<field name="tax_estimate_ids" />
</page>
</notebook>
Expand Down