[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:
parent
70ed972e23
commit
4b78dc4447
1 changed files with 17 additions and 11 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import logging
|
||||
|
||||
from odoo import api, models
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -15,26 +15,32 @@ class ProductPricelist(models.Model):
|
|||
def _compute_price_rule(self, products, quantity, uom=None, date=False, **kwargs):
|
||||
ProductPricelistItem = self.env["product.pricelist.item"]
|
||||
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(
|
||||
"[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._name,
|
||||
quantity,
|
||||
)
|
||||
|
||||
|
||||
res = super()._compute_price_rule(
|
||||
products,
|
||||
quantity,
|
||||
uom=uom,
|
||||
date=date,
|
||||
**kwargs
|
||||
products, quantity, uom=uom, date=date, **kwargs
|
||||
)
|
||||
|
||||
|
||||
_logger.info(
|
||||
"[PRICELIST DEBUG] super()._compute_price_rule returned: %s",
|
||||
res,
|
||||
)
|
||||
|
||||
|
||||
new_res = res.copy()
|
||||
item_id = []
|
||||
for product_id, values in res.items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue