Skip to content

Commit

Permalink
[16.0][IMP] ddmrp: refactor method _quantity_in_progress to use _get_…
Browse files Browse the repository at this point in the history
…rfq_dlt logic
  • Loading branch information
AlexPForgeFlow committed Nov 4, 2024
1 parent 03909f2 commit 7ea6e4f
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,11 @@ def _quantity_in_progress(self):
"""Return Quantities that are not yet in virtual stock but should
be deduced from buffers (example: purchases created from buffers)"""
res = {}.fromkeys(self.ids, 0.0)
polines = self.env["purchase.order.line"].search(
[
("state", "in", ("draft", "sent", "to approve")),
("buffer_ids", "in", self.ids),
]
)
for poline in polines:
for buffer in poline.buffer_ids:
if buffer.id not in self.ids:
continue
res[buffer.id] += poline.product_uom._compute_quantity(
poline.product_qty, buffer.product_uom, round=False
for buffer in self:
polines = buffer._get_rfq_dlt(dlt_interval=None)
for line in polines:
res[buffer.id] += line.product_uom._compute_quantity(
line.product_qty, buffer.product_uom, round=False
)
return res

Expand Down Expand Up @@ -1685,9 +1678,9 @@ def _calc_incoming_dlt_qty(self):
outside_dlt_moves = self._search_stock_moves_incoming(outside_dlt=True)
rec.incoming_outside_dlt_qty = sum(outside_dlt_moves.mapped("product_qty"))
if rec.item_type == "purchased":
pols_outside_dlt = rec._get_rfq_dlt(outside_dlt=True)
pols_outside_dlt = rec._get_rfq_dlt(dlt_interval="outside")
rec.rfq_outside_dlt_qty = sum(pols_outside_dlt.mapped("product_qty"))
pols_inside_dlt = rec._get_rfq_dlt()
pols_inside_dlt = rec._get_rfq_dlt(dlt_interval="inside")
rec.rfq_inside_dlt_qty = sum(pols_inside_dlt.mapped("product_qty"))
else:
rec.rfq_outside_dlt_qty = 0.0
Expand Down Expand Up @@ -1839,19 +1832,23 @@ def action_view_supply_moves(self):
result["domain"] = [("id", "in", moves.ids)]
return result

def _get_rfq_dlt(self, outside_dlt=False):
def _get_rfq_dlt(self, dlt_interval=None):
self.ensure_one()
cut_date = self._get_incoming_supply_date_limit()
if not outside_dlt:
if dlt_interval == "outside":
pols = self.purchase_line_ids.filtered(
lambda l: l.date_planned <= fields.Datetime.to_datetime(cut_date)
and l.state in ("draft", "sent", "to approve")
)
else:
elif dlt_interval == "inside":
pols = self.purchase_line_ids.filtered(
lambda l: l.date_planned > fields.Datetime.to_datetime(cut_date)
and l.state in ("draft", "sent", "to approve")
)
else:
pols = self.purchase_line_ids.filtered(
lambda l: l.state in ("draft", "sent", "to approve")
)
return pols

def action_view_supply_moves_inside_dlt_window(self):
Expand All @@ -1870,15 +1867,15 @@ def action_view_supply_moves_outside_dlt_window(self):

def action_view_supply_rfq_inside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
pols = self._get_rfq_dlt()
pols = self._get_rfq_dlt(dlt_interval="inside")

Check warning on line 1870 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1870

Added line #L1870 was not covered by tests
pos = pols.mapped("order_id")
result["context"] = {}
result["domain"] = [("id", "in", pos.ids)]
return result

def action_view_supply_rfq_outside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
pols = self._get_rfq_dlt(outside_dlt=True)
pols = self._get_rfq_dlt(dlt_interval="outside")

Check warning on line 1878 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1878

Added line #L1878 was not covered by tests
pos = pols.mapped("order_id")
result["context"] = {}
result["domain"] = [("id", "in", pos.ids)]
Expand Down

0 comments on commit 7ea6e4f

Please sign in to comment.