Skip to content

Commit

Permalink
[IMP] ddmrp: Add 'total_outside_dlt_qty' to split incoming moves than…
Browse files Browse the repository at this point in the history
… rfqs.

Maintain two buttons to alert for supplies out of DLT.
The first one shows 'Stock Pickings' and the second one shows 'RFQs'.
  • Loading branch information
BernatPForgeFlow committed Aug 25, 2023
1 parent 16e18ff commit e676412
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
34 changes: 32 additions & 2 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,13 @@ def _compute_order_spike_threshold(self):
for rec in self:
rec.order_spike_threshold = 0.5 * rec.red_zone_qty

@api.depends("incoming_outside_dlt_qty", "rfq_outside_dlt_qty")
def _compute_total_incoming_outside_dlt_qty(self):
for rec in self:
rec.total_incoming_outside_dlt_qty = (

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L930

Added line #L930 was not covered by tests
rec.incoming_outside_dlt_qty + rec.rfq_outside_dlt_qty
)

def _get_manufactured_bom(self, limit=1):
locations = self.env["stock.location"].search(
[("id", "child_of", [self.location_id.id])]
Expand Down Expand Up @@ -1168,12 +1175,21 @@ def _compute_product_vendor_code(self):
string="Incoming (Outside DLT)",
readonly=True,
)
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_outside_dlt_qty = fields.Float(
string="RFQ Qty (Outside DLT)",
readonly=True,
help="Request for Quotation total quantity that is planned outside of "
"the DLT horizon.",
)
total_incoming_outside_dlt_qty = fields.Float(
compute="_compute_total_incoming_outside_dlt_qty"
)
net_flow_position = fields.Float(
string="Net flow position",
digits="Product Unit of Measure",
Expand Down Expand Up @@ -1670,12 +1686,18 @@ def _calc_incoming_dlt_qty(self):
# 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_inside_dlt_qty = sum(pols.mapped("product_qty"))
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"))
else:
rec.rfq_inside_dlt_qty = 0.0
rec.rfq_outside_dlt_qty = 0.0
return True

Expand Down Expand Up @@ -1817,8 +1839,8 @@ def _search_purchase_order_lines_incoming(self, outside_dlt=False):
)
return pols

def action_view_supply(self, outside_dlt=False):
if self.item_type == "purchased":
def action_view_supply(self, outside_dlt=False, view_rfq=False):
if self.item_type == "purchased" and view_rfq:
pols = self._search_purchase_order_lines_incoming(outside_dlt)
moves = self._search_stock_moves_incoming(outside_dlt)
while moves.mapped("move_orig_ids"):
Expand All @@ -1830,6 +1852,8 @@ def action_view_supply(self, outside_dlt=False):
result["domain"] = [("id", "in", pos.ids)]
elif self.item_type == "manufactured":
moves = self._search_stock_moves_incoming(outside_dlt)
while moves.mapped("move_orig_ids"):
moves = moves.mapped("move_orig_ids")

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1856

Added line #L1856 was not covered by tests
mos = moves.mapped("production_id")
result = self.env["ir.actions.actions"]._for_xml_id(
"mrp.mrp_production_action"
Expand All @@ -1852,6 +1876,12 @@ def action_view_supply_inside_dlt_window(self):
def action_view_supply_outside_dlt_window(self):
return self.action_view_supply(outside_dlt=True)

def action_view_rfq_inside_dlt_window(self):
return self.action_view_supply(view_rfq=True)

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1880

Added line #L1880 was not covered by tests

def action_view_rfq_outside_dlt_window(self):
return self.action_view_supply(outside_dlt=True, view_rfq=True)

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1883

Added line #L1883 was not covered by tests

def action_view_qualified_demand_pickings(self):
moves = self.qualified_demand_stock_move_ids
picks = moves.mapped("picking_id")
Expand Down
57 changes: 48 additions & 9 deletions ddmrp/views/stock_buffer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
string="Incoming Outside DLT"
optional="hide"
/>
<field
name="rfq_outside_dlt_qty"
string="RFQ Qty Outside DLT"
optional="hide"
/>
<button
title="Open Non-completed Moves"
name="open_moves"
Expand All @@ -74,10 +69,28 @@
name="action_view_supply_outside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0), ('rfq_outside_dlt_qty', '=', 0)]}"
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0)]}"
/>
<field name="rfq_inside_dlt_qty" invisible="1" />
<field name="rfq_outside_dlt_qty" invisible="1" />
<button
title="Some RFQ quantities are inside the DLT Horizon and may require confirming.
Press this button to display the involved RFQs"
name="action_view_rfq_inside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
/>
<button
title="No stock available on source location for distributed buffer"
title="Some RFQ quantities are outside of the DLT Horizon and may require rescheduling.
Press this button to display the involved RFQs"
name="action_view_rfq_outside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('rfq_outside_dlt_qty', '=', 0)]}"
/>
<button
title="No stock available in source location for distributed buffer"
name="action_dummy"
icon="fa-warning"
type="object"
Expand Down Expand Up @@ -389,21 +402,47 @@
type="object"
attrs="{'invisible': [('incoming_dlt_qty', '=', 0)]}"
/>
<field
name="incoming_outside_dlt_qty"
invisible="1"
/>
<field name="rfq_inside_dlt_qty" invisible="1" />
<div
class="o_row"
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
>
<button
title="Some RFQ quantities are inside the DLT Horizon and may require confirming.
Press this button to display the involved RFQs"
name="action_view_rfq_inside_dlt_window"
icon="fa-warning"
type="object"
/>
</div>
<field name="rfq_outside_dlt_qty" invisible="1" />
<div
class="o_row"
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0), ('rfq_outside_dlt_qty', '=', 0)]}"
attrs="{'invisible':[('total_incoming_outside_dlt_qty', '=', 0)]}"
>
<button
title="Some incoming quantities are outside of the DLT Horizon and may require rescheduling.
Press this button to display the involved supply orders"
name="action_view_supply_outside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0)]}"
/>
<button
title="Some RFQ quantities are outside of the DLT Horizon and may require rescheduling.
Press this button to display the involved RFQs"
name="action_view_rfq_outside_dlt_window"
icon="fa-warning"
type="object"
attrs="{'invisible':[('rfq_outside_dlt_qty', '=', 0)]}"
/>
(Outside DLT:
<field
name="incoming_outside_dlt_qty"
name="total_incoming_outside_dlt_qty"
invisible="0"
/>
)
Expand Down

0 comments on commit e676412

Please sign in to comment.