Skip to content

Commit

Permalink
Merge PR #494 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Nov 25, 2024
2 parents 5479a39 + 2a3f8e3 commit 8c03cd9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 28 deletions.
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 @@ 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 @@ -1196,6 +1189,17 @@ def _compute_product_vendor_code(self):
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 @@ -1679,17 +1683,15 @@ 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":
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 @@ -1837,18 +1839,22 @@ 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 == "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 @@ -1868,15 +1874,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")
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")
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 @@ -80,6 +80,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 @@ -89,6 +90,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 @@ -472,6 +482,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

0 comments on commit 8c03cd9

Please sign in to comment.