purchase_order_product_recommendation_supermarket: fix error when first order. fix day average previous period

This commit is contained in:
Luis 2025-06-23 17:51:46 +02:00
parent 8045bd4f67
commit e8f11f25a6

View file

@ -79,6 +79,8 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
if orders[-1].effective_date
else orders[-1].date_planned.date()
)
else:
self.date_last_order = False
dates = [o.date_order.date() for o in orders if o.date_order]
if len(dates) < 2:
@ -160,7 +162,7 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
days = self._get_total_days()
prev_date_end = self.date_begin - timedelta(days=1)
prev_date_begin = prev_date_end - timedelta(days=days)
prev_date_begin = self.date_begin - timedelta(days=days)
domain = self.with_context(
{
"period_date_begin": prev_date_begin,
@ -179,7 +181,6 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
"period_date_end": prev_date_end,
}
)._get_days_out_of_stock(product_id)
print(days_with_stock)
res["units_avg_delivered_prev"] = (
res["units_delivered_prev"] / days_with_stock
if days_with_stock != 0