diff --git a/l10n_br_fiscal/models/stock_price_mixin.py b/l10n_br_fiscal/models/stock_price_mixin.py index a2eaa1179dca..af7fa5d5ac67 100644 --- a/l10n_br_fiscal/models/stock_price_mixin.py +++ b/l10n_br_fiscal/models/stock_price_mixin.py @@ -9,51 +9,81 @@ class StockPriceMixin(models.AbstractModel): _name = "l10n_br_fiscal.stock.price.mixin" _description = "Stock Price Mixin" + freight_value_to_stock = fields.Boolean( + string="freight_value_to_stock", + default=True, + ) + + insurance_value_to_stock = fields.Boolean( + string="insurance_value_to_stock", + default=True, + ) + + other_value_to_stock = fields.Boolean( + string="other_value_to_stock", + default=True, + ) + issqn_tax_is_creditable = fields.Boolean( string="ISSQN Creditável", - default=False, + default=lambda self: self.valuation_via_stock_price, ) irpj_tax_is_creditable = fields.Boolean( string="IRPJ Creditável", - default=False, + default=lambda self: self.valuation_via_stock_price, ) icmsst_tax_is_creditable = fields.Boolean( string="ICMS ST Creditável", - default=False, + default=lambda self: self.valuation_via_stock_price, ) - 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") + icms_tax_is_creditable = fields.Boolean( + string="ICMS Creditável", + default=lambda self: self.valuation_via_stock_price, + ) + ipi_tax_is_creditable = fields.Boolean( + string="IPI Creditável", + default=lambda self: self.valuation_via_stock_price, + ) + cofins_tax_is_creditable = fields.Boolean( + string="COFINS Creditável", + default=lambda self: self.valuation_via_stock_price, + ) + pis_tax_is_creditable = fields.Boolean( + string="PIS Creditável", + default=lambda self: self.valuation_via_stock_price, + ) @api.onchange("icms_cst_id") def _onchange_icms_cst_id(self): - self.icms_tax_is_creditable = self.icms_cst_id.default_creditable_tax + if self.valuation_via_stock_price: + 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 + if self.valuation_via_stock_price: + 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 + if self.valuation_via_stock_price: + 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 + if self.valuation_via_stock_price: + 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: - 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 + company_default = self.company_id.stock_valuation_via_stock_price + return company_default valuation_via_stock_price = fields.Boolean( string="Valuation Via Stock Price", @@ -63,14 +93,16 @@ def _default_valuation_stock_price(self): " * Usar True para valor de estoque líquido (sem imposto)", ) - currency_id = fields.Many2one( + stock_price_br_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" + string="Stock Price", + compute="_compute_stock_price_br", + currency_field="stock_price_br_currency_id", ) @api.depends( @@ -84,6 +116,9 @@ def _default_valuation_stock_price(self): "ipi_tax_is_creditable", "cofins_tax_is_creditable", "pis_tax_is_creditable", + "freight_value_to_stock", + "insurance_value_to_stock", + "other_value_to_stock", ) def _compute_stock_price_br(self): """Subtract creditable taxes from stock price.""" @@ -96,18 +131,22 @@ def _compute_stock_price_br(self): if record.fiscal_operation_line_id and record.product_uom_qty: price = record.amount_total - if not record.valuation_via_stock_price: - continue + if not record.freight_value_to_stock: + price -= record.freight_value + if not record.insurance_value_to_stock: + price -= record.insurance_value + if not record.other_value_to_stock: + price -= record.other_value for tax in record.fiscal_tax_ids: - if hasattr(record, "%s_tax_is_creditable" % (tax.tax_domain,)): + try: 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)) + except AttributeError: + pass price_precision = self.env["decimal.precision"].precision_get( "Product Price" diff --git a/l10n_br_purchase_stock/models/purchase_order.py b/l10n_br_purchase_stock/models/purchase_order.py index d28159cbbc68..296cdf96ff01 100644 --- a/l10n_br_purchase_stock/models/purchase_order.py +++ b/l10n_br_purchase_stock/models/purchase_order.py @@ -17,6 +17,19 @@ class PurchaseOrder(models.Model): compute="_compute_get_button_create_invoice_invisible" ) + total_cost_of_goods_purchased = fields.Monetary( + string="Cost of Goods Purchased", + compute="_compute_cogp_amount", + ) + + @api.depends("order_line", "order_line.stock_price_br") + def _compute_cogp_amount(self): + for record in self: + cogp = 0 + for line in record.order_line: + cogp += line.stock_price_br + record.total_cost_of_goods_purchased = cogp + @api.depends("state", "invoice_status") def _compute_get_button_create_invoice_invisible(self): for record in self: diff --git a/l10n_br_purchase_stock/views/purchase_order.xml b/l10n_br_purchase_stock/views/purchase_order.xml index f570bfd58e20..5ded040157ef 100644 --- a/l10n_br_purchase_stock/views/purchase_order.xml +++ b/l10n_br_purchase_stock/views/purchase_order.xml @@ -31,18 +31,69 @@ - - - + + - + + + + + + + + + + + +
+ + Frete é custo de estoque? + Frete + é custo de estoque? +
+ + +
+ + Seguro é custo de estoque? + Seguro + é custo de estoque? +
+ + +
+ + Outras.Desp. é custo de estoque? + Outras.Desp. + é custo de estoque? +
+
+ diff --git a/l10n_br_stock_account/models/res_company.py b/l10n_br_stock_account/models/res_company.py index 47484e04a936..aaf75f708b37 100644 --- a/l10n_br_stock_account/models/res_company.py +++ b/l10n_br_stock_account/models/res_company.py @@ -21,3 +21,11 @@ class ResCompany(models.Model): comodel_name="l10n_br_fiscal.operation", domain=[("state", "=", "approved"), ("fiscal_operation_type", "=", "out")], ) + + stock_valuation_via_stock_price = fields.Boolean( + string="Valuation Via Stock Price", + default=True, + 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)", + ) diff --git a/l10n_br_stock_account/models/stock_move.py b/l10n_br_stock_account/models/stock_move.py index ed82661c5678..84382c092c3f 100644 --- a/l10n_br_stock_account/models/stock_move.py +++ b/l10n_br_stock_account/models/stock_move.py @@ -222,10 +222,7 @@ 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 - ): + elif self.fiscal_operation_id.fiscal_operation_type == "in": result = self.stock_price_br return result diff --git a/l10n_br_stock_account/views/res_company_view.xml b/l10n_br_stock_account/views/res_company_view.xml index f2f12aaace8d..bc5d7503e05b 100644 --- a/l10n_br_stock_account/views/res_company_view.xml +++ b/l10n_br_stock_account/views/res_company_view.xml @@ -13,6 +13,7 @@ + diff --git a/l10n_br_stock_account/views/stock_picking.xml b/l10n_br_stock_account/views/stock_picking.xml index 58ae4978d8a1..78096a870410 100644 --- a/l10n_br_stock_account/views/stock_picking.xml +++ b/l10n_br_stock_account/views/stock_picking.xml @@ -128,23 +128,64 @@ + + + + + + + +
+ + Frete é custo de estoque? + Frete é custo de estoque? +
+ +
+ + Seguro é custo de estoque? + Seguro é custo de estoque? +
+ - - +
+ + Outras.Desp. é custo de estoque? + Outras.Desp. é custo de estoque? +
+ @@ -210,26 +251,25 @@ -