diff --git a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py
index 230adcf..37ab0a4 100644
--- a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py
+++ b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py
@@ -158,6 +158,37 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
if len(found_scrapped):
res["units_scrapped"] = found_scrapped[0]["qty_done"]
+ days = self._get_total_days()
+ prev_date_end = self.date_begin - timedelta(days=1)
+ prev_date_begin = prev_date_end - timedelta(days=days)
+ domain = self.with_context(
+ {
+ "period_date_begin": prev_date_begin,
+ "period_date_end": prev_date_end,
+ }
+ )._get_move_line_domain(product_id, src="internal", dst="customer")
+ found_previous_period = self.env["stock.move.line"].read_group(
+ domain, ["product_id", "qty_done"], ["product_id"]
+ )
+ if len(found_previous_period):
+ res["units_delivered_prev"] = found_previous_period[0]["qty_done"]
+ if self.ignore_zero_stock_days:
+ days_with_stock = days - self.with_context(
+ {
+ "period_date_begin": prev_date_begin,
+ "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
+ else 1
+ )
+ else:
+ res["units_avg_delivered_prev"] = (
+ found_previous_period[0]["qty_done"] / days if days != 0 else 1
+ )
return res
def _get_days_out_of_stock(self, product):
@@ -166,8 +197,8 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
where the given product had zero or negative stock (qty_available).
"""
days_out_of_stock = 0
- date_from = self.date_begin
- date_to = self.date_end
+ date_from = self.env.context.get("period_date_begin", self.date_begin)
+ date_to = self.env.context.get("period_date_end", self.date_end)
if not date_from or not date_to:
return 0
# Loop through each day in the range
@@ -237,6 +268,13 @@ class PurchaseOrderRecommendationLine(models.TransientModel):
compute="_compute_stock_duration",
readonly=True,
)
+ units_delivered_prev = fields.Float(
+ readonly=True,
+ )
+ units_avg_delivered_prev = fields.Float(
+ digits="Product Unit of Measure",
+ readonly=True,
+ )
@api.depends("units_included", "product_id")
def _compute_subtotal_amount(self):
diff --git a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.xml b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.xml
index 5766795..d00bc32 100644
--- a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.xml
+++ b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.xml
@@ -32,6 +32,8 @@
+
+