Skip to content

Commit 8c03cd9

Browse files
committed
Merge PR #494 into 16.0
Signed-off-by LoisRForgeFlow
2 parents 5479a39 + 2a3f8e3 commit 8c03cd9

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

ddmrp/models/stock_buffer.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,11 @@ def _quantity_in_progress(self):
158158
"""Return Quantities that are not yet in virtual stock but should
159159
be deduced from buffers (example: purchases created from buffers)"""
160160
res = {}.fromkeys(self.ids, 0.0)
161-
polines = self.env["purchase.order.line"].search(
162-
[
163-
("state", "in", ("draft", "sent", "to approve")),
164-
("buffer_ids", "in", self.ids),
165-
]
166-
)
167-
for poline in polines:
168-
for buffer in poline.buffer_ids:
169-
if buffer.id not in self.ids:
170-
continue
171-
res[buffer.id] += poline.product_uom._compute_quantity(
172-
poline.product_qty, buffer.product_uom, round=False
161+
for buffer in self:
162+
polines = buffer._get_rfq_dlt(dlt_interval=None)
163+
for line in polines:
164+
res[buffer.id] += line.product_uom._compute_quantity(
165+
line.product_qty, buffer.product_uom, round=False
173166
)
174167
return res
175168

@@ -1196,6 +1189,17 @@ def _compute_product_vendor_code(self):
11961189
help="Request for Quotation total quantity that is planned outside of "
11971190
"the DLT horizon.",
11981191
)
1192+
rfq_inside_dlt_qty = fields.Float(
1193+
string="RFQ Qty (Inside DLT)",
1194+
readonly=True,
1195+
help="Request for Quotation total quantity that is planned inside of "
1196+
"the DLT horizon.",
1197+
)
1198+
rfq_total_qty = fields.Float(
1199+
string="RFQ Total Qty",
1200+
readonly=True,
1201+
help="Request for Quotation total quantity that is planned",
1202+
)
11991203
net_flow_position = fields.Float(
12001204
digits="Product Unit of Measure",
12011205
readonly=True,
@@ -1679,17 +1683,15 @@ def _calc_incoming_dlt_qty(self):
16791683
outside_dlt_moves = self._search_stock_moves_incoming(outside_dlt=True)
16801684
rec.incoming_outside_dlt_qty = sum(outside_dlt_moves.mapped("product_qty"))
16811685
if rec.item_type == "purchased":
1682-
cut_date = rec._get_incoming_supply_date_limit()
1683-
# FIXME: filter using order_id.state while
1684-
# https://github.com/odoo/odoo/pull/58966 is not merged.
1685-
# Can be changed in v14.
1686-
pols = rec.purchase_line_ids.filtered(
1687-
lambda l: l.date_planned > fields.Datetime.to_datetime(cut_date)
1688-
and l.order_id.state in ("draft", "sent")
1689-
)
1690-
rec.rfq_outside_dlt_qty = sum(pols.mapped("product_qty"))
1686+
pols_outside_dlt = rec._get_rfq_dlt(dlt_interval="outside")
1687+
rec.rfq_outside_dlt_qty = sum(pols_outside_dlt.mapped("product_qty"))
1688+
pols_inside_dlt = rec._get_rfq_dlt(dlt_interval="inside")
1689+
rec.rfq_inside_dlt_qty = sum(pols_inside_dlt.mapped("product_qty"))
1690+
rec.rfq_total_qty = rec.rfq_inside_dlt_qty + rec.rfq_outside_dlt_qty
16911691
else:
16921692
rec.rfq_outside_dlt_qty = 0.0
1693+
rec.rfq_inside_dlt_qty = 0.0
1694+
rec.rfq_total_qty = 0.0
16931695
rec.incoming_total_qty = rec.incoming_dlt_qty + rec.incoming_outside_dlt_qty
16941696
return True
16951697

@@ -1837,18 +1839,22 @@ def action_view_supply_moves(self):
18371839
result["domain"] = [("id", "in", moves.ids)]
18381840
return result
18391841

1840-
def _get_rfq_dlt(self, outside_dlt=False):
1842+
def _get_rfq_dlt(self, dlt_interval=None):
18411843
self.ensure_one()
18421844
cut_date = self._get_incoming_supply_date_limit()
1843-
if not outside_dlt:
1845+
if dlt_interval == "inside":
18441846
pols = self.purchase_line_ids.filtered(
18451847
lambda l: l.date_planned <= fields.Datetime.to_datetime(cut_date)
1846-
and l.state in ("draft", "sent")
1848+
and l.state in ("draft", "sent", "to approve")
18471849
)
1848-
else:
1850+
elif dlt_interval == "outside":
18491851
pols = self.purchase_line_ids.filtered(
18501852
lambda l: l.date_planned > fields.Datetime.to_datetime(cut_date)
1851-
and l.state in ("draft", "sent")
1853+
and l.state in ("draft", "sent", "to approve")
1854+
)
1855+
else:
1856+
pols = self.purchase_line_ids.filtered(
1857+
lambda l: l.state in ("draft", "sent", "to approve")
18521858
)
18531859
return pols
18541860

@@ -1868,15 +1874,15 @@ def action_view_supply_moves_outside_dlt_window(self):
18681874

18691875
def action_view_supply_rfq_inside_dlt_window(self):
18701876
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
1871-
pols = self._get_rfq_dlt()
1877+
pols = self._get_rfq_dlt(dlt_interval="inside")
18721878
pos = pols.mapped("order_id")
18731879
result["context"] = {}
18741880
result["domain"] = [("id", "in", pos.ids)]
18751881
return result
18761882

18771883
def action_view_supply_rfq_outside_dlt_window(self):
18781884
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
1879-
pols = self._get_rfq_dlt(outside_dlt=True)
1885+
pols = self._get_rfq_dlt(dlt_interval="outside")
18801886
pos = pols.mapped("order_id")
18811887
result["context"] = {}
18821888
result["domain"] = [("id", "in", pos.ids)]

ddmrp/views/stock_buffer_view.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
type="object"
8181
attrs="{'invisible':[('incoming_outside_dlt_qty', '=', 0)]}"
8282
/>
83+
<field name="rfq_total_qty" optional="hide" />
8384
<field name="rfq_outside_dlt_qty" invisible="1" />
8485
<button
8586
title="Some RFQ quantities are outside of the DLT Horizon and may require rescheduling.
@@ -89,6 +90,15 @@
8990
type="object"
9091
attrs="{'invisible':[('rfq_outside_dlt_qty', '=', 0)]}"
9192
/>
93+
<field name="rfq_inside_dlt_qty" optional="hide" />
94+
<button
95+
title="Some RFQs are inside of the DLT Horizon and waiting validation to be accounted into the NFP.
96+
Press this button to display them."
97+
name="action_view_supply_rfq_inside_dlt_window"
98+
icon="fa-warning"
99+
type="object"
100+
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
101+
/>
92102
<button
93103
title="No stock available in source location for distributed buffer"
94104
name="action_dummy"
@@ -472,6 +482,15 @@
472482
type="object"
473483
attrs="{'invisible': ['|', ('qualified_demand', '=', 0), ('qualified_demand_mrp_move_ids', '=', [])]}"
474484
/>
485+
<field name="rfq_inside_dlt_qty" invisible="1" />
486+
<button
487+
title="Some RFQs are inside of the DLT Horizon and waiting validation to be accounted into the NFP.
488+
Press this button to display them."
489+
name="action_view_supply_rfq_inside_dlt_window"
490+
icon="fa-warning"
491+
type="object"
492+
attrs="{'invisible':[('rfq_inside_dlt_qty', '=', 0)]}"
493+
/>
475494
</div>
476495
<field name="net_flow_position" />
477496
<label for="net_flow_position_percent" />

0 commit comments

Comments
 (0)