diff --git a/product_catalog_tree/__manifest__.py b/product_catalog_tree/__manifest__.py index 0ae097572..cee11519e 100644 --- a/product_catalog_tree/__manifest__.py +++ b/product_catalog_tree/__manifest__.py @@ -30,6 +30,8 @@ "depends": [ "product", "stock", + "account", + "sale", ], "data": [ "views/product_product_views.xml", diff --git a/product_catalog_tree/models/product_product.py b/product_catalog_tree/models/product_product.py index a47c6aa59..6598360e6 100644 --- a/product_catalog_tree/models/product_product.py +++ b/product_catalog_tree/models/product_product.py @@ -25,6 +25,11 @@ class ProductProduct(models.Model): compute="_compute_catalog_supplier_uom", readonly=True, ) + product_catalog_price_taxed = fields.Float( + string="Order Price with taxes", + compute="_compute_product_catalog_price_taxed", + readonly=True, + ) def _compute_catalog_supplier_uom(self): """Obtener la UoM del proveedor si estamos en una orden de compra""" @@ -46,6 +51,46 @@ def _compute_catalog_supplier_uom(self): if seller and seller.product_uom_id: rec.product_catalog_supplier_uom = seller.product_uom_id.name + @api.depends("product_tmpl_id.taxes_id", "product_catalog_price") + @api.depends_context("company", "company_id", "order_id", "product_catalog_order_model") + def _compute_product_catalog_price_taxed(self): + """Calcula product_catalog_price con impuestos incluidos. + Usa los impuestos del producto aplicando la posición fiscal si existe, + igual que el resto de los campos de precio en Odoo. + """ + res_model = self.env.context.get("product_catalog_order_model") + order_id = self.env.context.get("order_id") + + for rec in self: + if not rec.product_catalog_price: + rec.product_catalog_price_taxed = 0.0 + continue + + # Obtener moneda, partner y compañía del contexto de la orden si está disponible + if res_model and order_id: + order = self.env[res_model].browse(order_id) + currency = order.currency_id if hasattr(order, "currency_id") else self.env.company.currency_id + partner = order.partner_id if hasattr(order, "partner_id") else self.env["res.partner"] + company_id = order.company_id.id if hasattr(order, "company_id") else self.env.company.id + + # Obtener impuestos del producto y aplicar posición fiscal (patrón estándar de Odoo) + taxes = rec.taxes_id.filtered(lambda x: x.company_id.id == company_id) + if hasattr(order, "fiscal_position_id") and order.fiscal_position_id: + taxes = order.fiscal_position_id.map_tax(taxes) + else: + currency = self.env.company.currency_id + partner = self.env["res.partner"] + company_id = self.env.context.get("company_id", self.env.company.id) + taxes = rec.taxes_id.filtered(lambda x: x.company_id.id == company_id) + + if taxes: + tax_result = taxes.sudo().compute_all( + rec.product_catalog_price, currency=currency, quantity=1.0, product=rec, partner=partner + ) + rec.product_catalog_price_taxed = tax_result["total_included"] + else: + rec.product_catalog_price_taxed = rec.product_catalog_price + def write(self, vals): """ Si en vals solo viene product_catalog_qty hacemos esto para que usuarios sin permiso de escribir diff --git a/product_catalog_tree/views/product_product_views.xml b/product_catalog_tree/views/product_product_views.xml index 47219fa3c..85bb03840 100644 --- a/product_catalog_tree/views/product_product_views.xml +++ b/product_catalog_tree/views/product_product_views.xml @@ -21,7 +21,8 @@ - + + @@ -35,4 +36,23 @@ + + product.view.kanban.catalog + product.product + + + + + + + + +
+
+ With taxes: +
+
+
+
+ diff --git a/product_price_taxes_included/views/product_product_views.xml b/product_price_taxes_included/views/product_product_views.xml index 563118f65..6887810b4 100644 --- a/product_price_taxes_included/views/product_product_views.xml +++ b/product_price_taxes_included/views/product_product_views.xml @@ -7,7 +7,11 @@ - + + diff --git a/product_ux/views/product_product_views.xml b/product_ux/views/product_product_views.xml index 90a0bd03c..4410d35bf 100644 --- a/product_ux/views/product_product_views.xml +++ b/product_ux/views/product_product_views.xml @@ -8,7 +8,7 @@ - +