Skip to content

Commit

Permalink
[ADD] stock_price_br and CST-level creditable taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Jul 4, 2024
1 parent a5982d6 commit 08e4cd1
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 6 deletions.
2 changes: 1 addition & 1 deletion l10n_br_fiscal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"l10n_br_fiscal_cfop_manager","Fiscal CFOP for Manager","model_l10n_br_fiscal_cfop","l10n_br_fiscal.group_manager",1,0,0,0
"l10n_br_fiscal_cfop_maintenance","Fiscal CFOP for Maintenance","model_l10n_br_fiscal_cfop","l10n_br_fiscal.group_data_maintenance",1,1,1,1
"l10n_br_fiscal_cst_user","Fiscal CST for User","model_l10n_br_fiscal_cst","l10n_br_fiscal.group_user",1,0,0,0
"l10n_br_fiscal_cst_manager","Fiscal CST for Manager","model_l10n_br_fiscal_cst","l10n_br_fiscal.group_manager",1,0,0,0
"l10n_br_fiscal_cst_manager","Fiscal CST for Manager","model_l10n_br_fiscal_cst","l10n_br_fiscal.group_manager",1,1,0,0
"l10n_br_fiscal_cst_maintenance","Fiscal CST for Maintenance","model_l10n_br_fiscal_cst","l10n_br_fiscal.group_data_maintenance",1,1,1,1
"l10n_br_fiscal_tax_group_user","Fiscal Tax Group for User","model_l10n_br_fiscal_tax_group","l10n_br_fiscal.group_user",1,0,0,0
"l10n_br_fiscal_tax_group_manager","Fiscal Tax Group for Manager","model_l10n_br_fiscal_tax_group","l10n_br_fiscal.group_manager",1,1,1,1
Expand Down
1 change: 1 addition & 0 deletions l10n_br_stock_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"views/stock_rule_view.xml",
"views/stock_picking_type_view.xml",
"views/res_company_view.xml",
"views/cst_view.xml",
# Wizards
"wizards/stock_invoice_onshipping_view.xml",
],
Expand Down
2 changes: 2 additions & 0 deletions l10n_br_stock_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (C) 2015 Renato Lima - Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import cst
from . import res_company
from . import stock_rule
from . import stock_picking_type
from . import stock_picking
from . import stock_price_mixin
from . import stock_move
from . import procurement_group
13 changes: 13 additions & 0 deletions l10n_br_stock_account/models/cst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2024 - Diego Paradeda - KMEE
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


class CST(models.Model):
_inherit = "l10n_br_fiscal.cst"

creditable_tax = fields.Boolean(
string="Creditable Tax?",
default=True,
)
11 changes: 10 additions & 1 deletion l10n_br_stock_account/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

class StockMove(models.Model):
_name = "stock.move"
_inherit = [_name, "l10n_br_fiscal.document.line.mixin"]
_inherit = [
_name,
"l10n_br_fiscal.document.line.mixin",
"l10n_br_stock_account.stock.price.mixin",
]

@api.model
def _default_fiscal_operation(self):
Expand Down Expand Up @@ -218,6 +222,11 @@ def _get_price_unit(self):
# e continua sendo feito abaixo?
if self.fiscal_operation_id.fiscal_operation_type == "out":
result = self.product_id.with_company(self.company_id).standard_price
elif (
self.fiscal_operation_id.fiscal_operation_type == "in"
and self.valuation_via_stock_price
):
result = self.stock_price_br

return result

Expand Down
76 changes: 76 additions & 0 deletions l10n_br_stock_account/models/stock_price_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (C) 2024 Diego Paradeda - KMEE <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models
from odoo.tools.float_utils import float_round

from odoo.addons.l10n_br_fiscal.constants.fiscal import TAX_DOMAIN_ICMS_SN


class StockPriceMixin(models.AbstractModel):
_name = "l10n_br_stock_account.stock.price.mixin"
_description = "Stock Price Mixin"

def _default_valuation_stock_price(self):
"""
Método para chavear o custo médio dos produtos entre:
- líquido de impostos
- com impostos (padrão do Odoo).
TODO: Posicionar o campo para o usuário poder interagir com esse chaveamento
a nível de company
"""
return True

valuation_via_stock_price = fields.Boolean(
string="Valuation Via Stock Price",
default=_default_valuation_stock_price,
help="Determina se o valor utilizado no custeamento automático será padrão do"
" Odoo ou com base no campo stock_price_br.\n\n"
" * Usar True para valor de estoque líquido (sem imposto)",
)

currency_id = fields.Many2one(
comodel_name="res.currency",
string="Currency",
default=lambda self: self.env.ref("base.BRL"),
)

stock_price_br = fields.Monetary(
string="Stock Price", compute="_compute_stock_price_br"
)

@api.depends("amount_total", "fiscal_tax_ids", "valuation_via_stock_price")
def _compute_stock_price_br(self):
"""Subtract creditable taxes from stock price."""
for record in self:
record.stock_price_br = 0

if not hasattr(record, "product_uom_qty"):
continue

Check warning on line 49 in l10n_br_stock_account/models/stock_price_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_price_mixin.py#L49

Added line #L49 was not covered by tests

if record.fiscal_operation_line_id and record.product_uom_qty:
price = record.amount_total

if not record.valuation_via_stock_price:
continue

Check warning on line 55 in l10n_br_stock_account/models/stock_price_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_stock_account/models/stock_price_mixin.py#L55

Added line #L55 was not covered by tests

for tax in record.fiscal_tax_ids:
if hasattr(record, "%s_tax_id" % (tax.tax_domain,)):
if hasattr(record, "%s_cst_id" % (tax.tax_domain,)):
cst_id = getattr(record, "%s_cst_id" % (tax.tax_domain,))
else:
# Para tax to tipo icmssn o CST fica no campo icms_cst_id
if tax.tax_domain in TAX_DOMAIN_ICMS_SN:
cst_id = record.icms_cst_id

if cst_id and cst_id.creditable_tax:
if not hasattr(record, "%s_value" % (tax.tax_domain)):
continue
price -= getattr(record, "%s_value" % (tax.tax_domain))

price_precision = self.env["decimal.precision"].precision_get(
"Product Price"
)
record.stock_price_br = float_round(
(price / record.product_uom_qty), precision_digits=price_precision
)
11 changes: 7 additions & 4 deletions l10n_br_stock_account/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -464,7 +465,9 @@ <h2><a class="toc-backref" href="#toc-entry-11">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-12">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
14 changes: 14 additions & 0 deletions l10n_br_stock_account/views/cst_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>

<record id="cst_form_inherit" model="ir.ui.view">
<field name="name">l10n_br_fiscal.cst.form</field>
<field name="model">l10n_br_fiscal.cst</field>
<field name="inherit_id" ref="l10n_br_fiscal.cst_form" />
<field name="arch" type="xml">
<field name="tax_group_id" position="after">
<field name="creditable_tax" />
</field>
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions l10n_br_stock_account/views/stock_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
name="other_value"
attrs="{'readonly': [('delivery_costs', '=', 'total')]}"
/>
<field name="stock_price_br" readonly="1" />
<field name="valuation_via_stock_price" />
</group>
</page>
<page name="fiscal_line_extra_info" string="Extra Info" />
Expand Down

0 comments on commit 08e4cd1

Please sign in to comment.