purchase_order_product_recommendation_supermarket: add delivered data from previous period
This commit is contained in:
parent
3e20de2309
commit
8045bd4f67
2 changed files with 42 additions and 2 deletions
|
|
@ -158,6 +158,37 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel):
|
||||||
if len(found_scrapped):
|
if len(found_scrapped):
|
||||||
res["units_scrapped"] = found_scrapped[0]["qty_done"]
|
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
|
return res
|
||||||
|
|
||||||
def _get_days_out_of_stock(self, product):
|
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).
|
where the given product had zero or negative stock (qty_available).
|
||||||
"""
|
"""
|
||||||
days_out_of_stock = 0
|
days_out_of_stock = 0
|
||||||
date_from = self.date_begin
|
date_from = self.env.context.get("period_date_begin", self.date_begin)
|
||||||
date_to = self.date_end
|
date_to = self.env.context.get("period_date_end", self.date_end)
|
||||||
if not date_from or not date_to:
|
if not date_from or not date_to:
|
||||||
return 0
|
return 0
|
||||||
# Loop through each day in the range
|
# Loop through each day in the range
|
||||||
|
|
@ -237,6 +268,13 @@ class PurchaseOrderRecommendationLine(models.TransientModel):
|
||||||
compute="_compute_stock_duration",
|
compute="_compute_stock_duration",
|
||||||
readonly=True,
|
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")
|
@api.depends("units_included", "product_id")
|
||||||
def _compute_subtotal_amount(self):
|
def _compute_subtotal_amount(self):
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@
|
||||||
<field name="units_scrapped" string="Qty scrapped" optional="hide" />
|
<field name="units_scrapped" string="Qty scrapped" optional="hide" />
|
||||||
<field name="stock_duration" string="Stock Duration" optional="hide" />
|
<field name="stock_duration" string="Stock Duration" optional="hide" />
|
||||||
<field name="days_without_stock" optional="hide" />
|
<field name="days_without_stock" optional="hide" />
|
||||||
|
<field name="units_delivered_prev" string="Prev Period" optional="hide" />
|
||||||
|
<field name="units_avg_delivered_prev" string="Avg Prev Period" optional="hide" />
|
||||||
<field name="packaging_id" optional="show" />
|
<field name="packaging_id" optional="show" />
|
||||||
<field name="packaging_contained_qty" string="Packaging Contained Qty" optional="hide" />
|
<field name="packaging_contained_qty" string="Packaging Contained Qty" optional="hide" />
|
||||||
<field name="subtotal_amount" string="Subtotal Amount" optional="hide" />
|
<field name="subtotal_amount" string="Subtotal Amount" optional="hide" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue