Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] ddmrp: add RFQ qty info inside of the DLT Horizon and RFQ total Qty #498

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,11 @@
"""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 @@ -1183,6 +1176,17 @@
help="Request for Quotation total quantity that is planned outside of "
"the DLT horizon.",
)
rfq_inside_dlt_qty = fields.Float(
string="RFQ Qty (Inside DLT)",
readonly=True,
help="Request for Quotation total quantity that is planned inside of "
"the DLT horizon.",
)
rfq_total_qty = fields.Float(
string="RFQ Total Qty",
readonly=True,
help="Request for Quotation total quantity that is planned",
)
net_flow_position = fields.Float(
digits="Product Unit of Measure",
readonly=True,
Expand Down Expand Up @@ -1668,17 +1672,15 @@
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":
cut_date = rec._get_incoming_supply_date_limit()
# FIXME: filter using order_id.state while
# https://github.com/odoo/odoo/pull/58966 is not merged.
# Can be changed in v14.
pols = rec.purchase_line_ids.filtered(
lambda l: l.date_planned > fields.Datetime.to_datetime(cut_date)
and l.order_id.state in ("draft", "sent")
)
rec.rfq_outside_dlt_qty = sum(pols.mapped("product_qty"))
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(dlt_interval="inside")
rec.rfq_inside_dlt_qty = sum(pols_inside_dlt.mapped("product_qty"))
rec.rfq_total_qty = rec.rfq_inside_dlt_qty + rec.rfq_outside_dlt_qty
else:
rec.rfq_outside_dlt_qty = 0.0
rec.rfq_inside_dlt_qty = 0.0
rec.rfq_total_qty = 0.0
rec.incoming_total_qty = rec.incoming_dlt_qty + rec.incoming_outside_dlt_qty
return True

Expand Down Expand Up @@ -1826,18 +1828,22 @@
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 == "inside":
pols = self.purchase_line_ids.filtered(
lambda l: l.date_planned <= fields.Datetime.to_datetime(cut_date)
and l.state in ("draft", "sent")
and l.state in ("draft", "sent", "to approve")
)
else:
elif 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")
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

Expand All @@ -1857,15 +1863,15 @@

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 1866 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1866

Added line #L1866 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 1874 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1874

Added line #L1874 was not covered by tests
pos = pols.mapped("order_id")
result["context"] = {}
result["domain"] = [("id", "in", pos.ids)]
Expand Down
19 changes: 19 additions & 0 deletions ddmrp/views/stock_buffer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
type="object"
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0)]}"
/>
<field name="rfq_total_qty" optional="hide" />
<field name="rfq_outside_dlt_qty" invisible="1" />
<button
title="Some RFQ quantities are outside of the DLT Horizon and may require rescheduling.
Expand All @@ -80,6 +81,15 @@
type="object"
attrs="{'invisible':[('rfq_outside_dlt_qty', '=', 0)]}"
/>
<field name="rfq_inside_dlt_qty" optional="hide" />
<button
title="Some RFQs are inside of the DLT Horizon and waiting validation to be accounted into the NFP.
Press this button to display them."
name="action_view_supply_rfq_inside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
/>
<button
title="No stock available in source location for distributed buffer"
name="action_dummy"
Expand Down Expand Up @@ -465,6 +475,15 @@
type="object"
attrs="{'invisible': ['|', ('qualified_demand', '=', 0), ('qualified_demand_mrp_move_ids', '=', [])]}"
/>
<field name="rfq_inside_dlt_qty" invisible="1" />
<button
title="Some RFQs are inside of the DLT Horizon and waiting validation to be accounted into the NFP.
Press this button to display them."
name="action_view_supply_rfq_inside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
/>
</div>
<field name="net_flow_position" />
<label for="net_flow_position_percent" />
Expand Down
Loading