[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:
parent
c308d538a3
commit
70ed972e23
1 changed files with 17 additions and 0 deletions
|
|
@ -55,6 +55,14 @@ class ProductTemplate(models.Model):
|
||||||
store=True,
|
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")
|
@api.depends("product_variant_ids.last_purchase_price_updated")
|
||||||
def _compute_last_purchase_price_updated(self):
|
def _compute_last_purchase_price_updated(self):
|
||||||
for template in self:
|
for template in self:
|
||||||
|
|
@ -139,6 +147,15 @@ class ProductTemplate(models.Model):
|
||||||
("product_variant_ids.last_purchase_price_compute_type", operator, value)
|
("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):
|
def action_update_list_price(self):
|
||||||
"""Delegate to product variants."""
|
"""Delegate to product variants."""
|
||||||
return self.product_variant_ids.action_update_list_price()
|
return self.product_variant_ids.action_update_list_price()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue