[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
|
import logging
|
||||||
|
|
||||||
from odoo import api, models
|
from odoo import models
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -16,18 +16,24 @@ class ProductPricelist(models.Model):
|
||||||
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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue