[FIX] product_sale_price_from_pricelist: Add last_purchase_price field to template

Added last_purchase_price computed field in product.template as an alias
to last_purchase_price_received. This field is required for compatibility
with Odoo's standard pricelist system which accesses template['last_purchase_price']
during price computation.

Fixes KeyError: 'last_purchase_price' in website shop controller.
This commit is contained in:
snt 2026-02-12 18:45:32 +01:00
parent c308d538a3
commit 70ed972e23

View file

@ -55,6 +55,14 @@ class ProductTemplate(models.Model):
store=True,
)
# Alias for backward compatibility with pricelist base price computation
last_purchase_price = fields.Float(
string="Last Purchase Price",
compute="_compute_last_purchase_price",
search="_search_last_purchase_price",
store=True,
)
@api.depends("product_variant_ids.last_purchase_price_updated")
def _compute_last_purchase_price_updated(self):
for template in self:
@ -139,6 +147,15 @@ class ProductTemplate(models.Model):
("product_variant_ids.last_purchase_price_compute_type", operator, value)
]
@api.depends("last_purchase_price_received")
def _compute_last_purchase_price(self):
"""Alias for backward compatibility with pricelist computations."""
for template in self:
template.last_purchase_price = template.last_purchase_price_received
def _search_last_purchase_price(self, operator, value):
return [("last_purchase_price_received", operator, value)]
def action_update_list_price(self):
"""Delegate to product variants."""
return self.product_variant_ids.action_update_list_price()