Criptomart/red-supermercados-coop#37 purchase_order_product_recommendation_supermarket: round qty_to_order when product_uom_categ_unit
This commit is contained in:
parent
a1f73dabe7
commit
25faab83bb
1 changed files with 23 additions and 7 deletions
|
|
@ -174,13 +174,21 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
|
|||
if days_with_stock != 0
|
||||
else 1
|
||||
)
|
||||
|
||||
if self.order_days != 0:
|
||||
qty_to_order = max(
|
||||
0,
|
||||
(self.order_days * res["units_avg_delivered"])
|
||||
- res["units_virtual_available"],
|
||||
uom_categ_unit = self.env.ref(
|
||||
"uom.product_uom_categ_unit", raise_if_not_found=False
|
||||
)
|
||||
if self.order_days != 0:
|
||||
qty_calc = (self.order_days * res["units_avg_delivered"]) - res[
|
||||
"units_virtual_available"
|
||||
]
|
||||
qty_to_order = max(0, qty_calc)
|
||||
# Round only if the UoM category is 'uom.product_uom_categ_unit'
|
||||
if (
|
||||
product_id.uom_po_id
|
||||
and uom_categ_unit
|
||||
and product_id.uom_po_id.category_id.id == uom_categ_unit.id
|
||||
):
|
||||
qty_to_order = math.ceil(qty_to_order)
|
||||
|
||||
# Force a minimum suggested quantity when forecast <= 0 and product configured
|
||||
# We apply this BEFORE packaging adjustment so packages logic can upscale it.
|
||||
|
|
@ -198,6 +206,14 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
|
|||
packaging_qty = product_id.packaging_ids[:1].qty
|
||||
if packaging_qty:
|
||||
qty_to_order = math.ceil(qty_to_order / packaging_qty) * packaging_qty
|
||||
# Round only if the UoM category is 'uom.product_uom_categ_unit'
|
||||
if (
|
||||
product_id.uom_po_id
|
||||
and uom_categ_unit
|
||||
and product_id.uom_po_id.category_id.id == uom_categ_unit.id
|
||||
):
|
||||
res["units_included"] = math.ceil(qty_to_order)
|
||||
else:
|
||||
res["units_included"] = qty_to_order
|
||||
|
||||
# Get quantities scrapped
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue