Skip to content

Commit

Permalink
[MIG] mrp_multi_level: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow committed Apr 4, 2024
1 parent 03d6936 commit fa027b5
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 73 deletions.
2 changes: 1 addition & 1 deletion mrp_multi_level/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "MRP Multi Level",
"version": "16.0.1.3.5",
"version": "17.0.1.0.0",
"development_status": "Production/Stable",
"license": "LGPL-3",
"author": "Ucamco, ForgeFlow, Odoo Community Association (OCA)",
Expand Down
16 changes: 11 additions & 5 deletions mrp_multi_level/demo/mrp_bom_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<field name="product_tmpl_id" ref="product_product_fp_1_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="sequence">5</field>
<field name="produce_delay">2</field>
</record>
<record id="mrp_bom_fp_1_line_pp_1" model="mrp.bom.line">
<field name="product_id" ref="product_product_pp_1" />
Expand All @@ -25,6 +26,7 @@
<field name="product_tmpl_id" ref="product_product_fp_2_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="sequence">5</field>
<field name="produce_delay">1</field>
</record>
<record id="mrp_bom_fp_2_line_sf_1" model="mrp.bom.line">
<field name="product_id" ref="product_product_sf_1" />
Expand All @@ -42,10 +44,11 @@
</record>

<!-- FP-3 -->
<record id="mrp_bom_fp_3" model="mrp.bom">
<record id="mrp_bom_fp_3" model="mrp.bom">
<field name="product_tmpl_id" ref="product_product_fp_3_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="sequence">5</field>
<field name="produce_delay">3</field>
</record>
<record id="mrp_bom_fp_3_line_sf_3" model="mrp.bom.line">
<field name="product_id" ref="product_product_sf_3" />
Expand All @@ -62,8 +65,8 @@
<field name="bom_id" ref="mrp_bom_fp_3" />
</record>

<!-- Customizable Desk -->
<record id="mrp_bom_product_4" model="mrp.bom">
<!-- Customizable Desk -->
<record id="mrp_bom_product_4" model="mrp.bom">
<field
name="product_tmpl_id"
ref="product.product_product_4_product_template"
Expand Down Expand Up @@ -120,6 +123,7 @@
<field name="product_tmpl_id" ref="product_product_sf_1_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="sequence">5</field>
<field name="produce_delay">1</field>
</record>
<record id="mrp_bom_sf_1_line_pp_1" model="mrp.bom.line">
<field name="product_id" ref="product_product_pp_1" />
Expand All @@ -140,6 +144,7 @@
<field name="product_tmpl_id" ref="product_product_sf_2_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="sequence">5</field>
<field name="produce_delay">3</field>
</record>
<record id="mrp_bom_sf_2_line_pp_2" model="mrp.bom.line">
<field name="product_id" ref="product_product_pp_2" />
Expand All @@ -149,11 +154,12 @@
<field name="bom_id" ref="mrp_bom_sf_2" />
</record>
<!-- SF-3 -->
<record id="mrp_bom_sf_3" model="mrp.bom">
<record id="mrp_bom_sf_3" model="mrp.bom">
<field name="product_tmpl_id" ref="product_product_sf_3_product_template" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="type">phantom</field>
<field name="type">phantom</field>
<field name="sequence">5</field>
<field name="produce_delay">3</field>
</record>
<record id="mrp_bom_sf_3_line_pp_3" model="mrp.bom.line">
<field name="product_id" ref="product_product_pp_3" />
Expand Down
9 changes: 1 addition & 8 deletions mrp_multi_level/demo/product_product_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">2</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand All @@ -18,7 +17,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">1</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand All @@ -30,7 +28,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">3</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand All @@ -42,10 +39,9 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">2</field>
</record>

<!-- Customizable Desk -->
<!-- Customizable Desk -->
<record id="product.product_product_4_product_template" model="product.template">
<field
name="route_ids"
Expand All @@ -58,7 +54,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">1</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand All @@ -70,7 +65,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">3</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand All @@ -82,7 +76,6 @@
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="produce_delay">3</field>
<field
name="route_ids"
eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"
Expand Down
1 change: 1 addition & 0 deletions mrp_multi_level/models/mrp_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ class MrpMove(models.Model):
stock_move_id = fields.Many2one(
comodel_name="stock.move", string="Stock Move", index=True
)
bom_id = fields.Many2one("mrp.bom")
27 changes: 10 additions & 17 deletions mrp_multi_level/models/product_mrp_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,18 @@ def _check_negatives(self):
if any(v < 0 for v in rec.values()):
raise ValidationError(_("You cannot use a negative number."))

Check warning on line 128 in mrp_multi_level/models/product_mrp_area.py

View check run for this annotation

Codecov / codecov/patch

mrp_multi_level/models/product_mrp_area.py#L128

Added line #L128 was not covered by tests

def name_get(self):
return [
(
area.id,
f"[{area.mrp_area_id.name}] {area.product_id.display_name}",
def _compute_display_name(self):
for area in self:
area.display_name = (
f"[{area.mrp_area_id.name}] {area.product_id.display_name}"
)
for area in self
]

@api.model
def _name_search(
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
):
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
if operator in ("ilike", "like", "=", "=like", "=ilike"):
args = expression.AND(
domain = expression.AND(

Check warning on line 139 in mrp_multi_level/models/product_mrp_area.py

View check run for this annotation

Codecov / codecov/patch

mrp_multi_level/models/product_mrp_area.py#L139

Added line #L139 was not covered by tests
[
args or [],
domain or [],
[
"|",
"|",
Expand All @@ -153,9 +148,7 @@ def _name_search(
],
]
)
return super(ProductMRPArea, self)._name_search(
name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid
)
return super()._name_search(name, domain, operator, limit, order)

Check warning on line 151 in mrp_multi_level/models/product_mrp_area.py

View check run for this annotation

Codecov / codecov/patch

mrp_multi_level/models/product_mrp_area.py#L151

Added line #L151 was not covered by tests

def _compute_mrp_lead_time(self):
produced = self.filtered(lambda r: r.supply_method == "manufacture")
Expand All @@ -164,7 +157,7 @@ def _compute_mrp_lead_time(self):
lambda r: r.supply_method in ("pull", "push", "pull_push")
)
for rec in produced:
rec.mrp_lead_time = rec.product_id.produce_delay
rec.mrp_lead_time = sum(rec.product_id.mapped("bom_ids.produce_delay"))
for rec in purchased:
rec.mrp_lead_time = rec.main_supplierinfo_id.delay
for rec in distributed:
Expand Down Expand Up @@ -220,7 +213,7 @@ def _compute_main_supplier(self):
"""Simplified and similar to procurement.rule logic."""
for rec in self.filtered(lambda r: r.supply_method == "buy"):
suppliers = rec.product_id.seller_ids.filtered(
lambda r: (not r.product_id or r.product_id == rec.product_id)
lambda r, rec=rec: (not r.product_id or r.product_id == rec.product_id)
and (not r.company_id or r.company_id == rec.company_id)
).sorted(lambda s: (s.sequence, -s.min_qty, s.price, s.id))
if not suppliers:
Expand Down
2 changes: 1 addition & 1 deletion mrp_multi_level/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def _get_inventory_fields_write(self):
"""
Adding field product_uom_id, inventory_quantity
"""
fields = super(StockQuant, self)._get_inventory_fields_write()
fields = super()._get_inventory_fields_write()
return fields + ["product_uom_id", "inventory_quantity"]
5 changes: 1 addition & 4 deletions mrp_multi_level/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def setUpClass(cls):
"name": "Test Top Seller",
"type": "product",
"list_price": 150.0,
"produce_delay": 5.0,
"route_ids": [(6, 0, [route_buy])],
"seller_ids": [(0, 0, {"partner_id": vendor1.id, "price": 20.0})],
}
Expand Down Expand Up @@ -214,7 +213,6 @@ def setUpClass(cls):
"uom_id": cls.env.ref("uom.product_uom_unit").id,
"uom_po_id": cls.env.ref("uom.product_uom_dozen").id,
"list_price": 150.0,
"produce_delay": 5.0,
"route_ids": [(6, 0, [route_buy])],
"seller_ids": [(0, 0, {"partner_id": vendor1.id, "price": 20.0})],
}
Expand All @@ -230,7 +228,6 @@ def setUpClass(cls):
"tracking": "lot",
"uom_id": cls.env.ref("uom.product_uom_unit").id,
"list_price": 100.0,
"produce_delay": 5.0,
"route_ids": [(6, 0, [route_buy])],
"seller_ids": [(0, 0, {"partner_id": vendor1.id, "price": 25.0})],
}
Expand Down Expand Up @@ -606,7 +603,7 @@ def _create_mo(cls, product, bom, date, qty=10.0):
mo_form.product_id = product
mo_form.bom_id = bom
mo_form.product_qty = qty
mo_form.date_planned_start = date
mo_form.date_start = date
mo = mo_form.save()
# Confirm the MO to generate stock moves:
mo.action_confirm()
Expand Down
14 changes: 7 additions & 7 deletions mrp_multi_level/tests/test_mrp_multi_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_06_procure_mo(self):
mos = self.mo_obj.search([("product_id", "=", self.fp_1.id)])
self.assertTrue(mos)
self.assertEqual(mos.product_qty, 100.0)
mo_date_start = fields.Date.to_date(mos.date_planned_start)
mo_date_start = fields.Date.to_date(mos.date_start)
self.assertEqual(mo_date_start, self.date_5)

def test_07_adjust_qty_to_order(self):
Expand Down Expand Up @@ -516,7 +516,7 @@ def test_18_priorize_safety_stock(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down Expand Up @@ -606,7 +606,7 @@ def test_20_prioritize_safety_stock_grouped_1(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down Expand Up @@ -687,7 +687,7 @@ def test_21_prioritize_safety_stock_grouped_2(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down Expand Up @@ -759,7 +759,7 @@ def test_22_prioritize_safety_stock_grouped_3(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_23_prioritize_safety_stock_with_mrp_moves_today(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down Expand Up @@ -844,7 +844,7 @@ def test_24_prioritize_safety_stock_with_mrp_moves_today_grouped(self):
},
]
self.assertEqual(len(expected), len(inventory))
for test_vals, inv in zip(expected, inventory):
for test_vals, inv in zip(expected, inventory, strict=True):
for key in test_vals:
self.assertEqual(
test_vals[key],
Expand Down
2 changes: 1 addition & 1 deletion mrp_multi_level/views/mrp_area_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<label for="name" class="oe_edit_only" />
<h1>
Expand Down
8 changes: 4 additions & 4 deletions mrp_multi_level/views/mrp_inventory_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<field name="supply_method" />
<field
name="main_supplier_id"
attrs="{'invisible': [('supply_method', '!=', 'buy')]}"
invisible="supply_method != 'buy'"
/>
<field name="date" />
</group>
Expand Down Expand Up @@ -53,7 +53,7 @@
<field name="final_on_hand_qty" />
<field name="to_procure" />
<button
attrs="{'invisible': [('planned_order_ids', '=', [])]}"
invisible="not planned_order_ids"
name="action_open_planned_orders"
type="object"
icon="fa-list"
Expand All @@ -65,9 +65,9 @@
name="%(mrp_multi_level.act_mrp_inventory_procure)d"
icon="fa-cogs"
type="action"
attrs="{'invisible':[('to_procure','&lt;=',0.0)]}"
invisible="to_procure &lt;= 0.0"
/>
<field name="planned_order_ids" invisible="1" />
<field name="planned_order_ids" column_invisible="True" />
<field name="supply_method" />
<field name="main_supplier_id" optional="hide" />
<field name="running_availability" />
Expand Down
22 changes: 8 additions & 14 deletions mrp_multi_level/views/mrp_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,34 @@
<field name="mrp_origin" />
<field
name="production_id"
attrs="{'invisible':[('mrp_origin', '!=', 'mo')]}"
invisible="mrp_origin != 'mo'"
/>
<field
name="purchase_order_id"
attrs="{'invisible':[('mrp_origin', '!=', 'po')]}"
invisible="mrp_origin != 'po'"
/>
<field
name="purchase_line_id"
attrs="{'invisible':[('mrp_origin', '!=', 'po')]}"
invisible="mrp_origin != 'po'"
/>
<field
name="stock_move_id"
attrs="{'invisible':[('mrp_origin', '!=', 'mv')]}"
invisible="mrp_origin != 'mv'"
/>
<field name="name" />
<field name="origin" />
</group>
<group>
<field name="mrp_date" />
<field
name="current_date"
attrs="{'invisible': [('current_date', '=', False)]}"
/>
<field
name="state"
attrs="{'invisible': [('state', '=', False)]}"
/>
<field name="current_date" invisible="not current_date" />
<field name="state" invisible="not state" />
<field
name="mrp_order_number"
attrs="{'invisible': [('mrp_order_number', '=', False)]}"
invisible="not mrp_order_number"
/>
<field
name="parent_product_id"
attrs="{'invisible': [('parent_product_id', '=', False)]}"
invisible="not parent_product_id"
/>
<field name="mrp_qty" />
<field name="current_qty" />
Expand Down
Loading

0 comments on commit fa027b5

Please sign in to comment.