[FIX] product_sale_price_from_pricelist: Handle product.template in _compute_price_rule

Added check to ensure _compute_price_rule always works with product.product.
When product.template records are passed, convert them to their variants
before processing. This prevents MissingError when browsing product.product
with template IDs.

Fixes: Record does not exist or has been deleted (Record: product.product(22,))
This commit is contained in:
snt 2026-02-12 18:48:13 +01:00
parent 70ed972e23
commit 4b78dc4447

View file

@ -4,7 +4,7 @@
import logging import logging
from odoo import api, models from odoo import models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -15,26 +15,32 @@ class ProductPricelist(models.Model):
def _compute_price_rule(self, products, quantity, uom=None, date=False, **kwargs): def _compute_price_rule(self, products, quantity, uom=None, date=False, **kwargs):
ProductPricelistItem = self.env["product.pricelist.item"] ProductPricelistItem = self.env["product.pricelist.item"]
ProductProduct = self.env["product.product"] ProductProduct = self.env["product.product"]
# Ensure we're working with product.product, not product.template
if products and products._name == "product.template":
# Convert templates to their variants
_logger.info(
"[PRICELIST DEBUG] Converting product.template to product.product: %s",
products.ids,
)
products = products.mapped("product_variant_ids")
_logger.info( _logger.info(
"[PRICELIST DEBUG] _compute_price_rule called with products=%s, quantity=%s", "[PRICELIST DEBUG] _compute_price_rule called with products=%s (model=%s), quantity=%s",
products.ids, products.ids,
products._name,
quantity, quantity,
) )
res = super()._compute_price_rule( res = super()._compute_price_rule(
products, products, quantity, uom=uom, date=date, **kwargs
quantity,
uom=uom,
date=date,
**kwargs
) )
_logger.info( _logger.info(
"[PRICELIST DEBUG] super()._compute_price_rule returned: %s", "[PRICELIST DEBUG] super()._compute_price_rule returned: %s",
res, res,
) )
new_res = res.copy() new_res = res.copy()
item_id = [] item_id = []
for product_id, values in res.items(): for product_id, values in res.items():