LaOsaCoop/Odoo16#6 fix product_sale_price_from_pricelist

This commit is contained in:
Luis 2025-07-09 17:28:28 +02:00
parent 8e7c2a74fd
commit cccd802e45
5 changed files with 58 additions and 6 deletions

View file

@ -1,5 +1,6 @@
from . import product_pricelist
from . import product_pricelist_item
from . import product_product
from . import product_template
from . import res_config
from . import stock_move

View file

@ -15,7 +15,12 @@ class ProductPricelist(models.Model):
def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):
ProductPricelistItem = self.env["product.pricelist.item"]
ProductProduct = self.env["product.product"]
res = super()._compute_price_rule(products, date=date, qty=1)
res = super()._compute_price_rule(
products,
qty=1,
uom=uom,
date=date,
)
new_res = res.copy()
item_id = []
for product_id, values in res.items():

View file

@ -9,6 +9,12 @@ class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item"
base = fields.Selection(
selection_add=[("last_purchase_price_received", "Last purchase price")],
ondelete={"last_purchase_price_received": "set default"},
selection_add=[("last_purchase_price", "Last purchase price")],
ondelete={"last_purchase_price": "set default"},
)
def _compute_price(self, product, quantity, uom, date, currency=None):
result = super()._compute_price(product, quantity, uom, date, currency)
if self.compute_price == "formula" and self.base == "last_purchase_price":
result = product.sudo().last_purchase_price_received
return result

View file

@ -0,0 +1,22 @@
from odoo import models
class ProductProduct(models.Model):
_inherit = "product.product"
def price_compute(
self, price_type, uom=None, currency=None, company=None, date=False
):
"""Return dummy not falsy prices when computation is done from supplier
info for avoiding error on super method. We will later fill these with
correct values.
"""
if price_type == "last_purchase_price":
return dict.fromkeys(self.ids, 1.0)
return super().price_compute(
price_type,
uom=uom,
currency=currency,
company=company,
date=date,
)

View file

@ -18,7 +18,6 @@ class ProductTemplate(models.Model):
)
list_price_theoritical = fields.Float(
"Theoritical price",
readonly=True,
company_dependent=True,
)
last_purchase_price_received = fields.Float(
@ -66,8 +65,14 @@ class ProductTemplate(models.Model):
partial_price = template.product_variant_id._get_price(
qty=1, pricelist=pricelist
)
template.list_price_theoritical = partial_price["value"]
template.last_purchase_price_updated = True
template.write(
{
"list_price_theoritical": partial_price[
template.product_variant_id.id
]["value"],
"last_purchase_price_updated": True,
}
)
else:
raise UserError(
_(
@ -79,3 +84,16 @@ class ProductTemplate(models.Model):
for template in self:
template.list_price = template.list_price_theoritical
template.last_purchase_price_updated = False
def price_compute(
self, price_type, uom=None, currency=None, company=False, date=False
):
"""Return dummy not falsy prices when computation is done from supplier
info for avoiding error on super method. We will later fill these with
correct values.
"""
if price_type == "last_purchase_price":
return dict.fromkeys(self.ids, 1.0)
return super().price_compute(
price_type, uom=uom, currency=currency, company=company, date=date
)