Skip to content

Commit bdb83a1

Browse files
[IMP] mrp_multi_level: add RfQ quantity and button to check RfQs
It is useful to now that the supply quantity might not be confirmed yet directly from the MRP inventory screen.
1 parent da004d7 commit bdb83a1

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

mrp_multi_level/models/mrp_inventory.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class MrpInventory(models.Model):
4848
date = fields.Date()
4949
demand_qty = fields.Float(string="Demand")
5050
supply_qty = fields.Float(string="Supply")
51+
rfq_qty = fields.Float(
52+
string="RfQ",
53+
help="Quantity on Request for Quotation.\n"
54+
"This quantity is included in the supply quantity "
55+
"but it is not confirmed yet.",
56+
)
5157
initial_on_hand_qty = fields.Float(
5258
string="Starting Inventory", group_operator="avg"
5359
)
@@ -137,3 +143,29 @@ def action_open_planned_orders(self):
137143
"view_mode": "tree,form",
138144
"domain": domain,
139145
}
146+
147+
def action_open_rfqs(self):
148+
self.ensure_one()
149+
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
150+
rfq_move_domain = [
151+
("mrp_type", "=", "s"),
152+
("mrp_origin", "=", "po"),
153+
("purchase_order_id.state", "in", ["draft", "sent", "to approve"]),
154+
]
155+
moves = self.product_mrp_area_id.mrp_move_ids.filtered_domain(rfq_move_domain)
156+
if self.date == date.today():
157+
moves = moves.filtered(
158+
lambda m: m.purchase_line_id.date_planned.date() in [self.date, False]
159+
)
160+
else:
161+
moves = moves.filtered(
162+
lambda m: m.purchase_line_id.date_planned.date() == self.date
163+
)
164+
records = moves.mapped("purchase_order_id")
165+
if len(records) != 1:
166+
result["domain"] = [("id", "in", records.ids)]
167+
else:
168+
res = self.env.ref("purchase.purchase_order_form", False)
169+
result["views"] = [(res and res.id or False, "form")]
170+
result["res_id"] = records[0].id
171+
return result

mrp_multi_level/tests/test_mrp_multi_level.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,11 @@ def test_15_units_case(self):
393393
)
394394
self.assertEqual(len(prod_uom_test_inventory_lines), 1)
395395
self.assertEqual(prod_uom_test_inventory_lines.supply_qty, 12.0)
396-
# Supply qty has to be 12 has a dozen of units are in a RFQ.
396+
# Supply qty has to be 12, a dozen of units are in a RFQ.
397+
self.assertEqual(prod_uom_test_inventory_lines.rfq_qty, 12.0)
398+
# check that the action opens the correct RfQ:
399+
res = prod_uom_test_inventory_lines.action_open_rfqs()
400+
self.assertEqual(res["res_id"], self.po_uom.id)
397401

398402
def test_16_phantom_comp_planning(self):
399403
"""

mrp_multi_level/views/mrp_inventory_views.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<field name="initial_on_hand_qty" />
2828
<field name="demand_qty" />
2929
<field name="supply_qty" />
30+
<field name="rfq_qty" />
3031
<field name="final_on_hand_qty" />
3132
<field name="to_procure" />
3233
<field name="uom_id" groups="uom.group_uom" />
@@ -50,6 +51,14 @@
5051
<field name="initial_on_hand_qty" />
5152
<field name="demand_qty" />
5253
<field name="supply_qty" />
54+
<field name="rfq_qty" optional="hide" />
55+
<button
56+
attrs="{'invisible': [('rfq_qty', '&lt;=', 0.0)]}"
57+
name="action_open_rfqs"
58+
type="object"
59+
icon="fa-credit-card"
60+
title="Requests for Quotation"
61+
/>
5362
<field name="final_on_hand_qty" />
5463
<field name="to_procure" />
5564
<button

mrp_multi_level/wizards/mrp_multi_level.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,19 @@ def _get_supply_groups(self, product_mrp_area):
786786
params = {"mrp_product": product_mrp_area.id}
787787
return query, params
788788

789+
@api.model
790+
def _get_rfq_supply_groups(self, product_mrp_area):
791+
query = """
792+
SELECT mrp_date, sum(mrp_qty)
793+
FROM mrp_move
794+
WHERE product_mrp_area_id = %(mrp_product)s
795+
AND mrp_type = 's' AND mrp_origin = 'po'
796+
AND state in ('draft', 'sent', 'to approve')
797+
GROUP BY mrp_date
798+
"""
799+
params = {"mrp_product": product_mrp_area.id}
800+
return query, params
801+
789802
@api.model
790803
def _get_planned_order_groups(self, product_mrp_area):
791804
query = """
@@ -807,13 +820,16 @@ def _prepare_mrp_inventory_data(
807820
demand_qty_by_date,
808821
supply_qty_by_date,
809822
planned_qty_by_date,
823+
rfq_supply_qty_by_date,
810824
):
811825
"""Return dict to create mrp.inventory records on MRP Multi Level Scheduler"""
812826
mrp_inventory_data = {"product_mrp_area_id": product_mrp_area.id, "date": mdt}
813827
demand_qty = demand_qty_by_date.get(mdt, 0.0)
814828
mrp_inventory_data["demand_qty"] = abs(demand_qty)
815829
supply_qty = supply_qty_by_date.get(mdt, 0.0)
816830
mrp_inventory_data["supply_qty"] = abs(supply_qty)
831+
rfq_supply_qty = rfq_supply_qty_by_date.get(mdt, 0.0)
832+
mrp_inventory_data["rfq_qty"] = abs(rfq_supply_qty)
817833
mrp_inventory_data["initial_on_hand_qty"] = on_hand_qty
818834
if product_mrp_area.supply_method != "phantom":
819835
on_hand_qty += supply_qty + demand_qty
@@ -841,6 +857,12 @@ def _init_mrp_inventory(self, product_mrp_area):
841857
self.env.cr.execute(query, params)
842858
for mrp_date, qty in self.env.cr.fetchall():
843859
supply_qty_by_date[mrp_date] = qty
860+
# Read RFQ Supply:
861+
rfq_supply_qty_by_date = {}
862+
query, params = self._get_rfq_supply_groups(product_mrp_area)
863+
self.env.cr.execute(query, params)
864+
for mrp_date, qty in self.env.cr.fetchall():
865+
rfq_supply_qty_by_date[mrp_date] = qty
844866
# Read planned orders:
845867
planned_qty_by_date = {}
846868
query, params = self._get_planned_order_groups(product_mrp_area)
@@ -875,6 +897,7 @@ def _init_mrp_inventory(self, product_mrp_area):
875897
demand_qty_by_date,
876898
supply_qty_by_date,
877899
planned_qty_by_date,
900+
rfq_supply_qty_by_date,
878901
)
879902
mrp_inventory_vals.append(mrp_inventory_data)
880903
if mrp_inventory_vals:

0 commit comments

Comments
 (0)