Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
8db59cb6 by Cédric Krier at 2022-12-29T13:37:12+01:00
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
- - - - -
1 changed file:
- modules/sale_stock_quantity/sale.py
Changes:
=====================================
modules/sale_stock_quantity/sale.py
=====================================
@@ -211,6 +211,7 @@
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,6 +227,5 @@
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)
@@ -231,6 +231,9 @@
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(
@@ -233,9 +236,9 @@
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,
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/8db59cb61ec841476836e38bc027688bde5b9789
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/8db59cb61ec841476836e38bc027688bde5b9789
You're receiving this email because of your account on foss.heptapod.net.