LaOsaCoop/Odoo16#6 fix product_sale_price_from_pricelist
This commit is contained in:
parent
8e7c2a74fd
commit
cccd802e45
5 changed files with 58 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from . import product_pricelist
|
from . import product_pricelist
|
||||||
from . import product_pricelist_item
|
from . import product_pricelist_item
|
||||||
|
from . import product_product
|
||||||
from . import product_template
|
from . import product_template
|
||||||
from . import res_config
|
from . import res_config
|
||||||
from . import stock_move
|
from . import stock_move
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@ class ProductPricelist(models.Model):
|
||||||
def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):
|
def _compute_price_rule(self, products, qty, 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"]
|
||||||
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()
|
new_res = res.copy()
|
||||||
item_id = []
|
item_id = []
|
||||||
for product_id, values in res.items():
|
for product_id, values in res.items():
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,12 @@ class ProductPricelistItem(models.Model):
|
||||||
_inherit = "product.pricelist.item"
|
_inherit = "product.pricelist.item"
|
||||||
|
|
||||||
base = fields.Selection(
|
base = fields.Selection(
|
||||||
selection_add=[("last_purchase_price_received", "Last purchase price")],
|
selection_add=[("last_purchase_price", "Last purchase price")],
|
||||||
ondelete={"last_purchase_price_received": "set default"},
|
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
|
||||||
|
|
|
||||||
22
product_sale_price_from_pricelist/models/product_product.py
Normal file
22
product_sale_price_from_pricelist/models/product_product.py
Normal 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,
|
||||||
|
)
|
||||||
|
|
@ -18,7 +18,6 @@ class ProductTemplate(models.Model):
|
||||||
)
|
)
|
||||||
list_price_theoritical = fields.Float(
|
list_price_theoritical = fields.Float(
|
||||||
"Theoritical price",
|
"Theoritical price",
|
||||||
readonly=True,
|
|
||||||
company_dependent=True,
|
company_dependent=True,
|
||||||
)
|
)
|
||||||
last_purchase_price_received = fields.Float(
|
last_purchase_price_received = fields.Float(
|
||||||
|
|
@ -66,8 +65,14 @@ class ProductTemplate(models.Model):
|
||||||
partial_price = template.product_variant_id._get_price(
|
partial_price = template.product_variant_id._get_price(
|
||||||
qty=1, pricelist=pricelist
|
qty=1, pricelist=pricelist
|
||||||
)
|
)
|
||||||
template.list_price_theoritical = partial_price["value"]
|
template.write(
|
||||||
template.last_purchase_price_updated = True
|
{
|
||||||
|
"list_price_theoritical": partial_price[
|
||||||
|
template.product_variant_id.id
|
||||||
|
]["value"],
|
||||||
|
"last_purchase_price_updated": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_(
|
_(
|
||||||
|
|
@ -79,3 +84,16 @@ class ProductTemplate(models.Model):
|
||||||
for template in self:
|
for template in self:
|
||||||
template.list_price = template.list_price_theoritical
|
template.list_price = template.list_price_theoritical
|
||||||
template.last_purchase_price_updated = False
|
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
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue