Skip to content
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: 2 additions & 0 deletions product_catalog_tree/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"depends": [
"product",
"stock",
"account",
"sale",
],
"data": [
"views/product_product_views.xml",
Expand Down
45 changes: 45 additions & 0 deletions product_catalog_tree/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down
22 changes: 21 additions & 1 deletion product_catalog_tree/views/product_product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
</field>
<!-- Agregar Order Price y UoM del proveedor -->
<field name="standard_price" position="after">
<field name="product_catalog_price"/>
<field name="product_catalog_price" optional="hide"/>
<field name="product_catalog_price_taxed" optional="show"/>
<field name="product_catalog_supplier_uom" optional="show" string="Supplier UoM"/>
</field>
<!-- Asegurar que existan los campos de UoM -->
Expand All @@ -35,4 +36,23 @@
</field>
</record>

<record id="product_view_kanban_catalog" model="ir.ui.view">
<field name="name">product.view.kanban.catalog</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_view_kanban_catalog"/>
<field name="arch" type="xml">
<!-- Agregar campos de precio del catálogo -->
<field name="id" position="after">
<field name="product_catalog_price"/>
<field name="product_catalog_price_taxed"/>
</field>
<!-- Agregar precio con impuestos después del div de precio -->
<div name="o_kanban_price" position="after">
<div class="text-muted small" t-if="record.product_catalog_price_taxed.raw_value">
With taxes: <t t-out="record.product_catalog_price_taxed.raw_value"/>
</div>
</div>
</field>
</record>

</odoo>
6 changes: 5 additions & 1 deletion product_price_taxes_included/views/product_product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<field name="inherit_id" ref="product.product_product_tree_view"></field>
<field name="arch" type="xml">
<field name="lst_price" position="after">
<field name="taxed_lst_price" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="taxed_lst_price"
widget="monetary"
options="{'currency_field': 'currency_id'}"
optional="hide"/>

</field>
</field>
</record>
Expand Down
2 changes: 1 addition & 1 deletion product_ux/views/product_product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="arch" type="xml">
<field name="standard_price" position="after">
<field name="pricelist_price"/>
<field name="pricelist_price" optional="hide"/>
</field>
</field>
</record>
Expand Down
Loading