Skip to content

Commit

Permalink
[ADD] tax creditable bool table
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Jul 8, 2024
1 parent 4e41b93 commit 5136afd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 18 deletions.
57 changes: 53 additions & 4 deletions l10n_br_fiscal/models/stock_price_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ class StockPriceMixin(models.AbstractModel):
_name = "l10n_br_fiscal.stock.price.mixin"
_description = "Stock Price Mixin"

issqn_tax_is_creditable = fields.Boolean(
string="ISSQN Creditável",
default=False,
)

irpj_tax_is_creditable = fields.Boolean(
string="IRPJ Creditável",
default=False,
)

icmsst_tax_is_creditable = fields.Boolean(
string="ICMS ST Creditável",
default=False,
)

icms_tax_is_creditable = fields.Boolean(string="ICMS Creditável")
ipi_tax_is_creditable = fields.Boolean(string="IPI Creditável")
cofins_tax_is_creditable = fields.Boolean(string="COFINS Creditável")
pis_tax_is_creditable = fields.Boolean(string="PIS Creditável")

@api.onchange("icms_cst_id")
def _onchange_icms_cst_id(self):
self.icms_tax_is_creditable = self.icms_cst_id.default_creditable_tax

@api.onchange("ipi_cst_id")
def _onchange_ipi_cst_id(self):
self.ipi_tax_is_creditable = self.ipi_cst_id.default_creditable_tax

@api.onchange("cofins_cst_id")
def _onchange_cofins_cst_id(self):
self.cofins_tax_is_creditable = self.cofins_cst_id.default_creditable_tax

@api.onchange("pis_cst_id")
def _onchange_pis_cst_id(self):
self.pis_tax_is_creditable = self.pis_cst_id.default_creditable_tax

def _default_valuation_stock_price(self):
"""
Método para chavear o custo médio dos produtos entre:
Expand Down Expand Up @@ -37,7 +73,18 @@ def _default_valuation_stock_price(self):
string="Stock Price", compute="_compute_stock_price_br"
)

@api.depends("amount_total", "fiscal_tax_ids", "valuation_via_stock_price")
@api.depends(
"amount_total",
"fiscal_tax_ids",
"valuation_via_stock_price",
"issqn_tax_is_creditable",
"irpj_tax_is_creditable",
"icmsst_tax_is_creditable",
"icms_tax_is_creditable",
"ipi_tax_is_creditable",
"cofins_tax_is_creditable",
"pis_tax_is_creditable",
)
def _compute_stock_price_br(self):
"""Subtract creditable taxes from stock price."""
for record in self:
Expand All @@ -53,9 +100,11 @@ def _compute_stock_price_br(self):
continue

for tax in record.fiscal_tax_ids:
if hasattr(record, "%s_tax_id" % (tax.tax_domain,)):
tax_id = getattr(record, "%s_tax_id" % (tax.tax_domain,))
if tax_id and tax_id.creditable_tax:
if hasattr(record, "%s_tax_is_creditable" % (tax.tax_domain,)):
creditable = getattr(
record, "%s_tax_is_creditable" % (tax.tax_domain,)
)
if creditable:
if not hasattr(record, "%s_value" % (tax.tax_domain)):
continue
price -= getattr(record, "%s_value" % (tax.tax_domain))
Expand Down
13 changes: 0 additions & 13 deletions l10n_br_fiscal/models/tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,6 @@ class Tax(models.Model):
("fiscal_tax_code_uniq", "unique (name)", "Tax already exists with this name !")
]

# Stock Price
creditable_tax = fields.Boolean(
string="Creditable Tax?",
default=lambda self: (
self.cst_in_id.default_creditable_tax if self.cst_in_id else False
),
)

@api.onchange("cst_in_id")
def _onchange_cst_in_id(self):
if self.cst_in_id:
self.creditable_tax = self.cst_in_id.default_creditable_tax

@api.model
def cst_from_tax(self, fiscal_operation_type=FISCAL_OUT):
self.ensure_one()
Expand Down
1 change: 0 additions & 1 deletion l10n_br_fiscal/views/tax_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<field name="tax_group_id" />
<field name="cst_in_id" />
<field name="cst_out_id" />
<field name="creditable_tax" />
</tree>
</field>
</record>
Expand Down
17 changes: 17 additions & 0 deletions l10n_br_purchase_stock/views/purchase_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
name="stock_price_br"
attrs="{'readonly': [('delivery_costs', '=', 'total')]}"
/>

</xpath>

<xpath expr="//page[@name='others']" position="inside">
<group name="tax_credits" string="Tax Credits">
<group>
<field name="icms_tax_is_creditable" />
<field name="ipi_tax_is_creditable" />
<field name="cofins_tax_is_creditable" />
<field name="pis_tax_is_creditable" />
</group>
<group>
<field name="icmsst_tax_is_creditable" />
<field name="issqn_tax_is_creditable" />
<field name="irpj_tax_is_creditable" />
</group>
</group>
</xpath>

</field>
Expand Down
13 changes: 13 additions & 0 deletions l10n_br_stock_account/views/stock_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@
<field name="stock_price_br" readonly="1" />
<field name="valuation_via_stock_price" />
</group>
<group name="tax_credits" string="Tax Credits">
<group>
<field name="icms_tax_is_creditable" />
<field name="ipi_tax_is_creditable" />
<field name="cofins_tax_is_creditable" />
<field name="pis_tax_is_creditable" />
</group>
<group>
<field name="icmsst_tax_is_creditable" />
<field name="issqn_tax_is_creditable" />
<field name="irpj_tax_is_creditable" />
</group>
</group>
</page>
<page name="fiscal_line_extra_info" string="Extra Info" />
<page name="accounting" string="Accounting">
Expand Down

0 comments on commit 5136afd

Please sign in to comment.