Convert line quantity into product default unit to compare with forecast

The forecast quantity on product is always in the default unit. So to make the
same test as on check stock quantity, we need to convert the line quantity
into the default product unit.

Closes #11958
This commit is contained in:
Cédric Krier
2022-12-29 13:37:12 +01:00
parent 1739d5ede3
commit 447d768cd5
+8 -5
View File
@@ -211,6 +211,7 @@ class Line(metaclass=PoolMeta):
Lang = pool.get('ir.lang')
Move = pool.get('stock.move')
Product = pool.get('product.product')
UoM = pool.get('product.uom')
lang = Lang.get()
if (self.sale_state == 'draft'
and self.sale
@@ -226,16 +227,18 @@ class Line(metaclass=PoolMeta):
locations = [self.sale.warehouse.id]
with Transaction().set_context(
locations=locations,
stock_date_end=sale_date,
uom=self.unit):
stock_date_end=sale_date):
product = Product(self.product.id)
if product.forecast_quantity < self.quantity:
quantity = UoM.compute_qty(
self.unit, self.quantity,
product.default_uom, round=False)
if product.forecast_quantity < quantity:
yield ('warning', gettext(
'sale_stock_quantity'
'.msg_product_forecast_quantity_lower',
forecast_quantity=lang.format_number_symbol(
product.forecast_quantity, self.unit,
self.unit.digits),
product.forecast_quantity, product.default_uom,
product.default_uom.digits),
product=self.product.rec_name,
quantity=lang.format_number_symbol(
self.quantity, self.unit,