From 70ed972e231a719f8c6067c6adb93faa935ea9f1 Mon Sep 17 00:00:00 2001 From: snt Date: Thu, 12 Feb 2026 18:45:32 +0100 Subject: [PATCH] [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. --- .../models/product_template.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/product_sale_price_from_pricelist/models/product_template.py b/product_sale_price_from_pricelist/models/product_template.py index 09ef270..8e80b4e 100644 --- a/product_sale_price_from_pricelist/models/product_template.py +++ b/product_sale_price_from_pricelist/models/product_template.py @@ -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()