-
+
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
diff --git a/mrp_multi_level/tests/test_mrp_multi_level.py b/mrp_multi_level/tests/test_mrp_multi_level.py
index 098b713b9..c417a1fe1 100644
--- a/mrp_multi_level/tests/test_mrp_multi_level.py
+++ b/mrp_multi_level/tests/test_mrp_multi_level.py
@@ -17,13 +17,13 @@ class TestMrpMultiLevel(SavepointCase):
cls.mo_obj = cls.env['mrp.production']
cls.po_obj = cls.env['purchase.order']
cls.product_obj = cls.env['product.product']
+ cls.product_mrp_area_obj = cls.env['product.mrp.area']
cls.partner_obj = cls.env['res.partner']
cls.stock_picking_obj = cls.env['stock.picking']
cls.estimate_obj = cls.env['stock.demand.estimate']
cls.mrp_multi_level_wiz = cls.env['mrp.multi.level']
cls.mrp_inventory_procure_wiz = cls.env['mrp.inventory.procure']
cls.mrp_inventory_obj = cls.env['mrp.inventory']
- cls.mrp_product_obj = cls.env['mrp.product']
cls.mrp_move_obj = cls.env['mrp.move']
cls.fp_1 = cls.env.ref('mrp_multi_level.product_product_fp_1')
@@ -32,6 +32,7 @@ class TestMrpMultiLevel(SavepointCase):
cls.sf_2 = cls.env.ref('mrp_multi_level.product_product_sf_2')
cls.pp_1 = cls.env.ref('mrp_multi_level.product_product_pp_1')
cls.pp_2 = cls.env.ref('mrp_multi_level.product_product_pp_2')
+ cls.mrp_area = cls.env.ref('mrp_multi_level.mrp_area_stock_wh0')
cls.vendor = cls.env.ref('mrp_multi_level.res_partner_lazer_tech')
cls.wh = cls.env.ref('stock.warehouse0')
cls.stock_location = cls.wh.lot_stock_id
@@ -54,22 +55,35 @@ class TestMrpMultiLevel(SavepointCase):
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 20.0})],
})
+ cls.product_mrp_area_obj.create({
+ 'product_id': cls.prod_test.id,
+ 'mrp_area_id': cls.mrp_area.id,
+ })
cls.prod_min = cls.product_obj.create({
'name': 'Product with minimum order qty',
'type': 'product',
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
+ })
+ cls.product_mrp_area_obj.create({
+ 'product_id': cls.prod_min.id,
+ 'mrp_area_id': cls.mrp_area.id,
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 0.0,
'mrp_qty_multiple': 1.0,
})
+
cls.prod_max = cls.product_obj.create({
'name': 'Product with maximum order qty',
'type': 'product',
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
+ })
+ cls.product_mrp_area_obj.create({
+ 'product_id': cls.prod_max.id,
+ 'mrp_area_id': cls.mrp_area.id,
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 100.0,
'mrp_qty_multiple': 1.0,
@@ -80,11 +94,14 @@ class TestMrpMultiLevel(SavepointCase):
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
+ })
+ cls.product_mrp_area_obj.create({
+ 'product_id': cls.prod_multiple.id,
+ 'mrp_area_id': cls.mrp_area.id,
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 500.0,
'mrp_qty_multiple': 25.0,
})
-
# Create test picking for FP-1 and FP-2:
res = cls.calendar.plan_days(7+1, datetime.today())
date_move = res.date()
@@ -244,16 +261,16 @@ class TestMrpMultiLevel(SavepointCase):
self.assertEqual(self.pp_1.llc, 2)
self.assertEqual(self.pp_2.llc, 2)
- def test_02_mrp_product(self):
+ def test_02_product_mrp_area(self):
"""Tests that mrp products are generated correctly."""
- mrp_product = self.mrp_product_obj.search([
+ product_mrp_area = self.product_mrp_area_obj.search([
('product_id', '=', self.pp_1.id)])
- self.assertEqual(mrp_product.supply_method, 'buy')
- self.assertEqual(mrp_product.main_supplier_id, self.vendor)
- self.assertEqual(mrp_product.mrp_qty_available, 10.0)
- mrp_product = self.mrp_product_obj.search([
+ self.assertEqual(product_mrp_area.supply_method, 'buy')
+ self.assertEqual(product_mrp_area.main_supplier_id, self.vendor)
+ self.assertEqual(product_mrp_area.qty_available, 10.0)
+ product_mrp_area = self.product_mrp_area_obj.search([
('product_id', '=', self.sf_1.id)])
- self.assertEqual(mrp_product.supply_method, 'manufacture')
+ self.assertEqual(product_mrp_area.supply_method, 'manufacture')
def test_03_mrp_moves(self):
"""Tests for mrp moves generated."""
@@ -265,11 +282,13 @@ class TestMrpMultiLevel(SavepointCase):
self.assertNotIn('s', moves.mapped('mrp_type'))
for move in moves:
self.assertTrue(move.mrp_move_up_ids)
- if move.mrp_move_up_ids.mrp_product_id.product_id == self.fp_1:
+ if move.mrp_move_up_ids.product_mrp_area_id.product_id == \
+ self.fp_1:
# Demand coming from FP-1
self.assertEqual(move.mrp_move_up_ids.mrp_action, 'mo')
self.assertEqual(move.mrp_qty, -200.0)
- elif move.mrp_move_up_ids.mrp_product_id.product_id == self.sf_1:
+ elif move.mrp_move_up_ids.product_mrp_area_id.product_id == \
+ self.sf_1:
# Demand coming from FP-2 -> SF-1
self.assertEqual(move.mrp_move_up_ids.mrp_action, 'mo')
if move.mrp_date == self.date_5:
@@ -299,21 +318,21 @@ class TestMrpMultiLevel(SavepointCase):
"""Tests MRP inventories created."""
# FP-1
fp_1_inventory_lines = self.mrp_inventory_obj.search(
- [('mrp_product_id.product_id', '=', self.fp_1.id)])
+ [('product_mrp_area_id.product_id', '=', self.fp_1.id)])
self.assertEqual(len(fp_1_inventory_lines), 1)
self.assertEqual(fp_1_inventory_lines.date, self.date_7)
self.assertEqual(fp_1_inventory_lines.demand_qty, 100.0)
self.assertEqual(fp_1_inventory_lines.to_procure, 100.0)
# FP-2
fp_2_line_1 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.fp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.fp_2.id),
('date', '=', self.date_7)])
self.assertEqual(len(fp_2_line_1), 1)
self.assertEqual(fp_2_line_1.demand_qty, 15.0)
self.assertEqual(fp_2_line_1.to_procure, 15.0)
# TODO: ask odoo to fix it... should be date10
fp_2_line_2 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.fp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.fp_2.id),
('date', '=', self.date_9)])
self.assertEqual(len(fp_2_line_2), 1)
self.assertEqual(fp_2_line_2.demand_qty, 0.0)
@@ -322,26 +341,26 @@ class TestMrpMultiLevel(SavepointCase):
# SF-1
sf_1_line_1 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.sf_1.id),
+ ('product_mrp_area_id.product_id', '=', self.sf_1.id),
('date', '=', self.date_6)])
self.assertEqual(len(sf_1_line_1), 1)
self.assertEqual(sf_1_line_1.demand_qty, 30.0)
self.assertEqual(sf_1_line_1.to_procure, 30.0)
sf_1_line_2 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.sf_1.id),
+ ('product_mrp_area_id.product_id', '=', self.sf_1.id),
('date', '=', self.date_9)])
self.assertEqual(len(sf_1_line_2), 1)
self.assertEqual(sf_1_line_2.demand_qty, 24.0)
self.assertEqual(sf_1_line_2.to_procure, 24.0)
# SF-2
sf_2_line_1 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.sf_2.id),
+ ('product_mrp_area_id.product_id', '=', self.sf_2.id),
('date', '=', self.date_6)])
self.assertEqual(len(sf_2_line_1), 1)
self.assertEqual(sf_2_line_1.demand_qty, 45.0)
self.assertEqual(sf_2_line_1.to_procure, 30.0)
sf_2_line_2 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.sf_2.id),
+ ('product_mrp_area_id.product_id', '=', self.sf_2.id),
('date', '=', self.date_9)])
self.assertEqual(len(sf_2_line_2), 1)
self.assertEqual(sf_2_line_2.demand_qty, 36.0)
@@ -349,39 +368,39 @@ class TestMrpMultiLevel(SavepointCase):
# PP-1
pp_1_line_1 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_1.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_1.id),
('date', '=', self.date_5)])
self.assertEqual(len(pp_1_line_1), 1)
self.assertEqual(pp_1_line_1.demand_qty, 290.0)
self.assertEqual(pp_1_line_1.to_procure, 280.0)
pp_1_line_2 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_1.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_1.id),
('date', '=', self.date_8)])
self.assertEqual(len(pp_1_line_2), 1)
self.assertEqual(pp_1_line_2.demand_qty, 72.0)
self.assertEqual(pp_1_line_2.to_procure, 72.0)
# PP-2
pp_2_line_1 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_2.id),
('date', '=', self.date_3)])
self.assertEqual(len(pp_2_line_1), 1)
self.assertEqual(pp_2_line_1.demand_qty, 90.0)
# 90.0 demand - 20.0 on hand - 5.0 on PO = 65.0
self.assertEqual(pp_2_line_1.to_procure, 65.0)
pp_2_line_2 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_2.id),
('date', '=', self.date_5)])
self.assertEqual(len(pp_2_line_2), 1)
self.assertEqual(pp_2_line_2.demand_qty, 360.0)
self.assertEqual(pp_2_line_2.to_procure, 360.0)
pp_2_line_3 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_2.id),
('date', '=', self.date_6)])
self.assertEqual(len(pp_2_line_3), 1)
self.assertEqual(pp_2_line_3.demand_qty, 108.0)
self.assertEqual(pp_2_line_3.to_procure, 108.0)
pp_2_line_4 = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.pp_2.id),
+ ('product_mrp_area_id.product_id', '=', self.pp_2.id),
('date', '=', self.date_8)])
self.assertEqual(len(pp_2_line_4), 1)
self.assertEqual(pp_2_line_4.demand_qty, 48.0)
@@ -398,11 +417,11 @@ class TestMrpMultiLevel(SavepointCase):
expected = [200.0, 290.0, 90.0, 0.0, 72.0, 0.0]
self.assertEqual(moves.mapped('running_availability'), expected)
# Actions counters for PP-1:
- mrp_product = self.mrp_product_obj.search([
- ('product_id', '=', self.pp_1.id)
- ])
- self.assertEqual(mrp_product.nbr_mrp_actions, 3)
- self.assertEqual(mrp_product.nbr_mrp_actions_4w, 3)
+ # product_mrp_area = self.product_mrp_area_obj.search([
+ # ('product_id', '=', self.pp_1.id)
+ # ]) # TODO
+ # self.assertEqual(product_mrp_area.nbr_mrp_actions, 3) # TODO
+ # self.assertEqual(product_mrp_area.nbr_mrp_actions_4w, 3) # TODO
def test_06_demand_estimates(self):
"""Tests demand estimates integration."""
@@ -428,7 +447,7 @@ class TestMrpMultiLevel(SavepointCase):
('product_id', '=', self.fp_1.id)])
self.assertFalse(mos)
mrp_inv = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.fp_1.id)])
+ ('product_mrp_area_id.product_id', '=', self.fp_1.id)])
self.mrp_inventory_procure_wiz.with_context({
'active_model': 'mrp.inventory',
'active_ids': mrp_inv.ids,
@@ -446,11 +465,11 @@ class TestMrpMultiLevel(SavepointCase):
maximum order quantities and quantity multiple are set."""
# minimum order quantity:
mrp_inv_min = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.prod_min.id)])
+ ('product_mrp_area_id.product_id', '=', self.prod_min.id)])
self.assertEqual(mrp_inv_min.to_procure, 50.0)
# maximum order quantity:
mrp_inv_max = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.prod_max.id)])
+ ('product_mrp_area_id.product_id', '=', self.prod_max.id)])
self.assertEqual(mrp_inv_max.to_procure, 150)
moves = self.mrp_move_obj.search([
('product_id', '=', self.prod_max.id),
@@ -461,7 +480,7 @@ class TestMrpMultiLevel(SavepointCase):
self.assertIn(50.0, moves.mapped('mrp_qty'))
# quantity multiple:
mrp_inv_multiple = self.mrp_inventory_obj.search([
- ('mrp_product_id.product_id', '=', self.prod_multiple.id)])
+ ('product_mrp_area_id.product_id', '=', self.prod_multiple.id)])
self.assertEqual(mrp_inv_multiple.to_procure, 125)
# TODO: test procure wizard: pos, multiple...
diff --git a/mrp_multi_level/views/mrp_area_view.xml b/mrp_multi_level/views/mrp_area_views.xml
similarity index 100%
rename from mrp_multi_level/views/mrp_area_view.xml
rename to mrp_multi_level/views/mrp_area_views.xml
diff --git a/mrp_multi_level/views/mrp_inventory_view.xml b/mrp_multi_level/views/mrp_inventory_views.xml
similarity index 92%
rename from mrp_multi_level/views/mrp_inventory_view.xml
rename to mrp_multi_level/views/mrp_inventory_views.xml
index 453b6da0f..0e804683e 100644
--- a/mrp_multi_level/views/mrp_inventory_view.xml
+++ b/mrp_multi_level/views/mrp_inventory_views.xml
@@ -11,7 +11,8 @@
-
+
+
@@ -35,7 +36,7 @@
-
+
@@ -59,7 +60,7 @@
-
+
@@ -72,7 +73,7 @@
-
+
@@ -84,7 +85,7 @@
-
+
@@ -93,7 +94,7 @@
+ context="{'group_by':'product_mrp_area_id'}"/>
-
+
-
-
-
-
diff --git a/mrp_multi_level/views/mrp_product_view.xml b/mrp_multi_level/views/mrp_product_view.xml
deleted file mode 100644
index 9854c446b..000000000
--- a/mrp_multi_level/views/mrp_product_view.xml
+++ /dev/null
@@ -1,161 +0,0 @@
-
-
-
-
- mrp.product.tree
- mrp.product
- tree
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- mrp.product.form
- mrp.product
- form
-
-
-
-
-
-
- mrp.filter.form
- mrp.product
- search
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MRP Products
- mrp.product
- ir.actions.act_window
- form
- tree,form
-
-
-
-
-
diff --git a/mrp_multi_level/views/product_mrp_area_views.xml b/mrp_multi_level/views/product_mrp_area_views.xml
new file mode 100644
index 000000000..11c8d02a0
--- /dev/null
+++ b/mrp_multi_level/views/product_mrp_area_views.xml
@@ -0,0 +1,114 @@
+
+
+
+
+ product.mrp.area.tree
+ product.mrp.area
+ tree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ product.mrp.area.form
+ product.mrp.area
+ form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ product.mrp.area.search
+ product.mrp.area
+ search
+
+
+
+
+
+
+
+
+
+
+ Product MRP Area Parameters
+ product.mrp.area
+ ir.actions.act_window
+ form
+ tree,form
+
+
+
+
+
diff --git a/mrp_multi_level/views/product_product_view.xml b/mrp_multi_level/views/product_product_view.xml
deleted file mode 100644
index 8bb1aed12..000000000
--- a/mrp_multi_level/views/product_product_view.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
- view.mrp.product.product.form
- product.product
-
- form
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/mrp_multi_level/views/product_product_views.xml b/mrp_multi_level/views/product_product_views.xml
new file mode 100644
index 000000000..ad24d4863
--- /dev/null
+++ b/mrp_multi_level/views/product_product_views.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ view.product.mrp.area.product.form
+ product.product
+
+ form
+
+
+
+
+
+
+
+
+
diff --git a/mrp_multi_level/views/product_template_view.xml b/mrp_multi_level/views/product_template_view.xml
deleted file mode 100644
index 97a45f396..000000000
--- a/mrp_multi_level/views/product_template_view.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
- product.template.product.form.mrp
- product.template
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/mrp_multi_level/views/product_template_views.xml b/mrp_multi_level/views/product_template_views.xml
new file mode 100644
index 000000000..1a5e9ddd5
--- /dev/null
+++ b/mrp_multi_level/views/product_template_views.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ product.template.product.form.mrp
+ product.template
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mrp_multi_level/views/stock_location_view.xml b/mrp_multi_level/views/stock_location_views.xml
similarity index 100%
rename from mrp_multi_level/views/stock_location_view.xml
rename to mrp_multi_level/views/stock_location_views.xml
diff --git a/mrp_multi_level/wizards/mrp_inventory_procure.py b/mrp_multi_level/wizards/mrp_inventory_procure.py
index 14b3bf6be..57fe8df8c 100644
--- a/mrp_multi_level/wizards/mrp_inventory_procure.py
+++ b/mrp_multi_level/wizards/mrp_inventory_procure.py
@@ -23,7 +23,7 @@ class MrpInventoryProcure(models.TransientModel):
'uom_id': mrp_inventory.uom_id.id,
'date_planned': mrp_inventory.date,
'mrp_inventory_id': mrp_inventory.id,
- 'product_id': mrp_inventory.mrp_product_id.product_id.id,
+ 'product_id': mrp_inventory.product_mrp_area_id.product_id.id,
'warehouse_id': mrp_inventory.mrp_area_id.warehouse_id.id,
'location_id': mrp_inventory.mrp_area_id.location_id.id,
}
@@ -57,12 +57,12 @@ class MrpInventoryProcure(models.TransientModel):
items = item_obj = self.env['mrp.inventory.procure.item']
for line in mrp_inventory_obj.browse(mrp_inventory_ids):
- max_order = line.mrp_product_id.mrp_maximum_order_qty
+ max_order = line.product_mrp_area_id.mrp_maximum_order_qty
qty_to_order = line.to_procure
if max_order and max_order < qty_to_order:
# split the procurement in batches:
while qty_to_order > 0.0:
- qty = line.mrp_product_id._adjust_qty_to_order(
+ qty = line.product_mrp_area_id._adjust_qty_to_order(
qty_to_order)
items += item_obj.create(self._prepare_item(line, qty))
qty_to_order -= qty
diff --git a/mrp_multi_level/wizards/mrp_inventory_procure_view.xml b/mrp_multi_level/wizards/mrp_inventory_procure_views.xml
similarity index 100%
rename from mrp_multi_level/wizards/mrp_inventory_procure_view.xml
rename to mrp_multi_level/wizards/mrp_inventory_procure_views.xml
diff --git a/mrp_multi_level/wizards/mrp_multi_level.py b/mrp_multi_level/wizards/mrp_multi_level.py
index 4244977de..2143d0ca5 100644
--- a/mrp_multi_level/wizards/mrp_multi_level.py
+++ b/mrp_multi_level/wizards/mrp_multi_level.py
@@ -17,38 +17,37 @@ class MultiLevelMrp(models.TransientModel):
# TODO: dates are not being correctly computed for supply...
@api.model
- def _prepare_mrp_product_data(self, product, mrp_area):
+ def _prepare_product_mrp_area_data(self, product_mrp_area):
qty_available = 0.0
product_obj = self.env['product.product']
# TODO: move mrp_qty_available computation, maybe unreserved??
location_ids = self.env['stock.location'].search(
- [('id', 'child_of', mrp_area.location_id.id)])
+ [('id', 'child_of', product_mrp_area.mrp_area_id.location_id.id)])
for location in location_ids:
product_l = product_obj.with_context(
- {'location': location.id}).browse(product.id)
+ {'location': location.id}).browse(
+ product_mrp_area.product_id.id)
qty_available += product_l.qty_available
return {
- 'mrp_area_id': mrp_area.id,
- 'product_id': product.id,
- 'mrp_qty_available': product.qty_available,
- 'mrp_llc': product.llc,
- 'name': '[%s] %s' % (mrp_area.name, product.display_name),
+ 'product_mrp_area_id': product_mrp_area.id,
+ 'mrp_qty_available': qty_available,
+ 'mrp_llc': product_mrp_area.product_id.llc,
}
@api.model
def _prepare_mrp_move_data_from_forecast(
- self, estimate, mrp_product, date):
+ self, estimate, product_mrp_area, date):
mrp_type = 'd'
origin = 'fc'
daily_qty = float_round(
estimate.daily_qty,
- precision_rounding=mrp_product.product_id.uom_id.rounding,
+ precision_rounding=product_mrp_area.product_id.uom_id.rounding,
rounding_method='HALF-UP')
return {
- 'mrp_area_id': mrp_product.mrp_area_id.id,
- 'product_id': mrp_product.product_id.id,
- 'mrp_product_id': mrp_product.id,
+ 'mrp_area_id': product_mrp_area.mrp_area_id.id,
+ 'product_id': product_mrp_area.product_id.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'production_id': None,
'purchase_order_id': None,
'purchase_line_id': None,
@@ -70,13 +69,7 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _prepare_mrp_move_data_from_stock_move(
- self, mrp_product, move, direction='in'):
- if not((move.location_id.usage == 'internal' and
- move.location_dest_id.usage != 'internal')
- or (move.location_id.usage != 'internal' and
- move.location_dest_id.usage == 'internal')):
- # TODO: not sure about this 'if'...
- return {}
+ self, product_mrp_area, move, direction='in'):
if direction == 'out':
mrp_type = 'd'
product_qty = -move.product_qty
@@ -117,9 +110,8 @@ class MultiLevelMrp(models.TransientModel):
mrp_date = datetime.date(datetime.strptime(
move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT))
return {
- 'mrp_area_id': mrp_product.mrp_area_id.id,
'product_id': move.product_id.id,
- 'mrp_product_id': mrp_product.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'production_id': mo,
'purchase_order_id': po,
'purchase_line_id': po_line,
@@ -141,12 +133,11 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _prepare_mrp_move_data_supply(
- self, mrp_product, qty, mrp_date_supply, mrp_action_date,
+ self, product_mrp_area, qty, mrp_date_supply, mrp_action_date,
mrp_action, name):
return {
- 'mrp_area_id': mrp_product.mrp_area_id.id,
- 'product_id': mrp_product.product_id.id,
- 'mrp_product_id': mrp_product.id,
+ 'product_id': product_mrp_area.product_id.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'production_id': None,
'purchase_order_id': None,
'purchase_line_id': None,
@@ -168,16 +159,16 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _prepare_mrp_move_data_bom_explosion(
self, product, bomline, qty, mrp_date_demand_2, bom, name):
- mrp_product = self._get_mrp_product_from_product_and_area(
+ product_mrp_area = self._get_product_mrp_area_from_product_and_area(
bomline.product_id, product.mrp_area_id)
- if not mrp_product:
+ if not product_mrp_area:
raise exceptions.Warning(
_("No MRP product found"))
return {
'mrp_area_id': product.mrp_area_id.id,
'product_id': bomline.product_id.id,
- 'mrp_product_id': mrp_product.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'production_id': None,
'purchase_order_id': None,
'purchase_line_id': None,
@@ -200,15 +191,15 @@ class MultiLevelMrp(models.TransientModel):
}
@api.model
- def create_move(self, mrp_product_id, mrp_date, mrp_qty, name):
+ def create_move(self, product_mrp_area_id, mrp_date, mrp_qty, name):
self = self.with_context(auditlog_disabled=True)
values = {}
if not isinstance(mrp_date, date):
mrp_date = fields.Date.from_string(mrp_date)
- if mrp_product_id.supply_method == 'buy':
- # if mrp_product_id.purchase_requisition:
+ if product_mrp_area_id.supply_method == 'buy':
+ # if product_mrp_area_id.purchase_requisition:
# mrp_action = 'pr'
# else:
mrp_action = 'po'
@@ -221,24 +212,24 @@ class MultiLevelMrp(models.TransientModel):
else:
mrp_date_supply = mrp_date
- calendar = mrp_product_id.mrp_area_id.calendar_id
- if calendar and mrp_product_id.mrp_lead_time:
+ calendar = product_mrp_area_id.mrp_area_id.calendar_id
+ if calendar and product_mrp_area_id.mrp_lead_time:
date_str = fields.Date.to_string(mrp_date)
dt = fields.Datetime.from_string(date_str)
res = calendar.plan_days(
- -1 * mrp_product_id.mrp_lead_time - 1, dt)
+ -1 * product_mrp_area_id.mrp_lead_time - 1, dt)
mrp_action_date = res.date()
else:
mrp_action_date = mrp_date - timedelta(
- days=mrp_product_id.mrp_lead_time)
+ days=product_mrp_area_id.mrp_lead_time)
qty_ordered = 0.00
qty_to_order = mrp_qty
while qty_ordered < mrp_qty:
- qty = mrp_product_id._adjust_qty_to_order(qty_to_order)
+ qty = product_mrp_area_id._adjust_qty_to_order(qty_to_order)
qty_to_order -= qty
move_data = self._prepare_mrp_move_data_supply(
- mrp_product_id, qty, mrp_date_supply, mrp_action_date,
+ product_mrp_area_id, qty, mrp_date_supply, mrp_action_date,
mrp_action, name)
mrpmove_id = self.env['mrp.move'].create(move_data)
qty_ordered = qty_ordered + qty
@@ -247,10 +238,10 @@ class MultiLevelMrp(models.TransientModel):
mrp_date_demand = mrp_action_date
if mrp_date_demand < date.today():
mrp_date_demand = date.today()
- if not mrp_product_id.product_id.bom_ids:
+ if not product_mrp_area_id.product_id.bom_ids:
continue
bomcount = 0
- for bom in mrp_product_id.product_id.bom_ids:
+ for bom in product_mrp_area_id.product_id.bom_ids:
if not bom.active or not bom.bom_line_ids:
continue
bomcount += 1
@@ -261,17 +252,17 @@ class MultiLevelMrp(models.TransientModel):
bomline.product_id.type != 'product':
continue
if self._exclude_from_mrp(
- mrp_product_id.mrp_area_id,
- bomline.product_id):
+ bomline.product_id,
+ product_mrp_area_id.mrp_area_id):
# Stop explosion.
continue
# TODO: review: mrp_transit_delay, mrp_inspection_delay
mrp_date_demand_2 = mrp_date_demand - timedelta(
- days=(mrp_product_id.mrp_transit_delay +
- mrp_product_id.mrp_inspection_delay))
+ days=(product_mrp_area_id.mrp_transit_delay +
+ product_mrp_area_id.mrp_inspection_delay))
move_data = \
self._prepare_mrp_move_data_bom_explosion(
- mrp_product_id, bomline, qty,
+ product_mrp_area_id, bomline, qty,
mrp_date_demand_2,
bom, name)
mrpmove_id2 = self.env['mrp.move'].create(move_data)
@@ -288,7 +279,6 @@ class MultiLevelMrp(models.TransientModel):
# installed
logger.info('START MRP CLEANUP')
self.env['mrp.move'].search([]).unlink()
- self.env['mrp.product'].search([]).unlink()
self.env['mrp.inventory'].search([]).unlink()
logger.info('END MRP CLEANUP')
return True
@@ -335,31 +325,25 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _calculate_mrp_applicable(self):
logger.info('CALCULATE MRP APPLICABLE')
- self.env['product.product'].search([]).write({'mrp_applicable': False})
- self.env['product.product'].search([
- ('type', '=', 'product'),
+ self.env['product.mrp.area'].search([]).write(
+ {'mrp_applicable': False})
+ self.env['product.mrp.area'].search([
+ ('product_id.type', '=', 'product'),
]).write({'mrp_applicable': True})
self._adjust_mrp_applicable()
- counter = self.env['product.product'].search([
+ counter = self.env['product.mrp.area'].search([
('mrp_applicable', '=', True)], count=True)
log_msg = 'END CALCULATE MRP APPLICABLE: %s' % counter
logger.info(log_msg)
return True
@api.model
- def _init_mrp_product(self, product, mrp_area):
-
- mrp_product_data = self._prepare_mrp_product_data(
- product, mrp_area)
- return self.env['mrp.product'].create(mrp_product_data)
-
- @api.model
- def _init_mrp_move_from_forecast(self, mrp_product):
+ def _init_mrp_move_from_forecast(self, product_mrp_area):
locations = self.env['stock.location'].search(
- [('id', 'child_of', mrp_product.mrp_area_id.location_id.id)])
+ [('id', 'child_of', product_mrp_area.mrp_area_id.location_id.id)])
today = fields.Date.today()
estimates = self.env['stock.demand.estimate'].search([
- ('product_id', '=', mrp_product.product_id.id),
+ ('product_id', '=', product_mrp_area.product_id.id),
('location_id', 'in', locations.ids),
('date_range_id.date_end', '>=', today)
])
@@ -373,19 +357,19 @@ class MultiLevelMrp(models.TransientModel):
while mrp_date <= date_end:
mrp_move_data = \
self._prepare_mrp_move_data_from_forecast(
- rec, mrp_product, mrp_date)
+ rec, product_mrp_area, mrp_date)
self.env['mrp.move'].create(mrp_move_data)
mrp_date += delta
return True
- # TODO: move this methods to mrp_product?? to be able to
+ # TODO: move this methods to product_mrp_area?? to be able to
# show moves with an action
@api.model
- def _in_stock_moves_domain(self, mrp_product):
+ def _in_stock_moves_domain(self, product_mrp_area):
locations = self.env['stock.location'].search(
- [('id', 'child_of', mrp_product.mrp_area_id.location_id.id)])
+ [('id', 'child_of', product_mrp_area.mrp_area_id.location_id.id)])
return [
- ('product_id', '=', mrp_product.product_id.id),
+ ('product_id', '=', product_mrp_area.product_id.id),
('state', 'not in', ['done', 'cancel']),
('product_qty', '>', 0.00),
('location_id', 'not in', locations.ids),
@@ -393,11 +377,11 @@ class MultiLevelMrp(models.TransientModel):
]
@api.model
- def _out_stock_moves_domain(self, mrp_product):
+ def _out_stock_moves_domain(self, product_mrp_area):
locations = self.env['stock.location'].search(
- [('id', 'child_of', mrp_product.mrp_area_id.location_id.id)])
+ [('id', 'child_of', product_mrp_area.mrp_area_id.location_id.id)])
return [
- ('product_id', '=', mrp_product.product_id.id),
+ ('product_id', '=', product_mrp_area.product_id.id),
('state', 'not in', ['done', 'cancel']),
('product_qty', '>', 0.00),
('location_id', 'in', locations.ids),
@@ -405,34 +389,35 @@ class MultiLevelMrp(models.TransientModel):
]
@api.model
- def _init_mrp_move_from_stock_move(self, mrp_product):
+ def _init_mrp_move_from_stock_move(self, product_mrp_area):
# TODO: Should we exclude the quantity done from the moves?
move_obj = self.env['stock.move']
mrp_move_obj = self.env['mrp.move']
- in_domain = self._in_stock_moves_domain(mrp_product)
+ in_domain = self._in_stock_moves_domain(product_mrp_area)
in_moves = move_obj.search(in_domain)
- out_domain = self._out_stock_moves_domain(mrp_product)
+ out_domain = self._out_stock_moves_domain(product_mrp_area)
out_moves = move_obj.search(out_domain)
if in_moves:
for move in in_moves:
move_data = self._prepare_mrp_move_data_from_stock_move(
- mrp_product, move, direction='in')
+ product_mrp_area, move, direction='in')
mrp_move_obj.create(move_data)
if out_moves:
for move in out_moves:
move_data = self._prepare_mrp_move_data_from_stock_move(
- mrp_product, move, direction='out')
+ product_mrp_area, move, direction='out')
mrp_move_obj.create(move_data)
return True
@api.model
- def _prepare_mrp_move_data_from_purchase_order(self, poline, mrp_product):
+ def _prepare_mrp_move_data_from_purchase_order(
+ self, poline, product_mrp_area):
mrp_date = date.today()
if fields.Date.from_string(poline.date_planned) > date.today():
mrp_date = fields.Date.from_string(poline.date_planned)
return {
'product_id': poline.product_id.id,
- 'mrp_product_id': mrp_product.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'production_id': None,
'purchase_order_id': poline.order_id.id,
'purchase_line_id': poline.id,
@@ -453,9 +438,9 @@ class MultiLevelMrp(models.TransientModel):
}
@api.model
- def _init_mrp_move_from_purchase_order(self, mrp_product):
+ def _init_mrp_move_from_purchase_order(self, product_mrp_area):
location_ids = self.env['stock.location'].search(
- [('id', 'child_of', mrp_product.mrp_area_id.location_id.id)])
+ [('id', 'child_of', product_mrp_area.mrp_area_id.location_id.id)])
picking_types = self.env['stock.picking.type'].search(
[('default_location_dest_id', 'in',
location_ids.ids)])
@@ -466,58 +451,64 @@ class MultiLevelMrp(models.TransientModel):
po_lines = self.env['purchase.order.line'].search(
[('order_id', 'in', orders.ids),
('product_qty', '>', 0.0),
- ('product_id', '=', mrp_product.product_id.id)])
+ ('product_id', '=', product_mrp_area.product_id.id)])
for line in po_lines:
mrp_move_data = \
self._prepare_mrp_move_data_from_purchase_order(
- line, mrp_product)
+ line, product_mrp_area)
self.env['mrp.move'].create(mrp_move_data)
@api.model
- def _get_mrp_product_from_product_and_area(self, product, mrp_area):
- return self.env['mrp.product'].search([
+ def _get_product_mrp_area_from_product_and_area(self, product, mrp_area):
+ return self.env['product.mrp.area'].search([
('product_id', '=', product.id),
('mrp_area_id', '=', mrp_area.id),
], limit=1)
@api.model
- def _init_mrp_move(self, mrp_product):
- self._init_mrp_move_from_forecast(mrp_product)
- self._init_mrp_move_from_stock_move(mrp_product)
- self._init_mrp_move_from_purchase_order(mrp_product)
+ def _init_mrp_move(self, product_mrp_area):
+ self._init_mrp_move_from_forecast(product_mrp_area)
+ self._init_mrp_move_from_stock_move(product_mrp_area)
+ self._init_mrp_move_from_purchase_order(product_mrp_area)
@api.model
- def _exclude_from_mrp(self, mrp_area, product):
+ def _exclude_from_mrp(self, product, mrp_area):
""" To extend with various logic where needed. """
- return product.mrp_exclude
+ product_mrp_area = self.env['product.mrp.area'].search(
+ [('product_id', '=', product.id),
+ ('mrp_area_id', '=', mrp_area.id)], limit=1)
+ if not product_mrp_area:
+ return True
+ return product_mrp_area.mrp_exclude
@api.model
def _mrp_initialisation(self):
logger.info('START MRP INITIALISATION')
mrp_areas = self.env['mrp.area'].search([])
- products = self.env['product.product'].search([
+ product_mrp_areas = self.env['product.mrp.area'].search([
('mrp_applicable', '=', True)])
init_counter = 0
for mrp_area in mrp_areas:
- for product in products:
- if self._exclude_from_mrp(mrp_area, product):
+ for product_mrp_area in product_mrp_areas.filtered(
+ lambda a: a.mrp_area_id == mrp_area):
+ if self._exclude_from_mrp(
+ product_mrp_area.product_id, mrp_area):
continue
init_counter += 1
log_msg = 'MRP INIT: %s - %s ' % (
- init_counter, product.default_code)
+ init_counter, product_mrp_area.display_name)
logger.info(log_msg)
- mrp_product = self._init_mrp_product(product, mrp_area)
- self._init_mrp_move(mrp_product)
+ self._init_mrp_move(product_mrp_area)
logger.info('END MRP INITIALISATION')
@api.model
- def _init_mrp_move_grouped_demand(self, nbr_create, mrp_product):
+ def _init_mrp_move_grouped_demand(self, nbr_create, product_mrp_area):
last_date = None
last_qty = 0.00
- onhand = mrp_product.mrp_qty_available
+ onhand = product_mrp_area.qty_available
move_ids = []
- for move in mrp_product.mrp_move_ids:
+ for move in product_mrp_area.mrp_move_ids:
move_ids.append(move.id)
for move_id in move_ids:
move_rec = self.env['mrp.move'].search(
@@ -529,18 +520,18 @@ class MultiLevelMrp(models.TransientModel):
datetime.strptime(
move.mrp_date, '%Y-%m-%d')) \
> last_date+timedelta(
- days=mrp_product.mrp_nbr_days):
+ days=product_mrp_area.mrp_nbr_days):
if (onhand + last_qty + move.mrp_qty) \
- < mrp_product.mrp_minimum_stock \
+ < product_mrp_area.mrp_minimum_stock \
or (onhand + last_qty) \
- < mrp_product.mrp_minimum_stock:
+ < product_mrp_area.mrp_minimum_stock:
name = 'Grouped Demand for %d Days' % \
- mrp_product.mrp_nbr_days
+ product_mrp_area.mrp_nbr_days
qtytoorder = \
- mrp_product.mrp_minimum_stock - \
- mrp_product - last_qty
+ product_mrp_area.mrp_minimum_stock - \
+ product_mrp_area - last_qty
cm = self.create_move(
- mrp_product_id=mrp_product.id,
+ product_mrp_area_id=product_mrp_area,
mrp_date=last_date,
mrp_qty=qtytoorder,
name=name)
@@ -550,9 +541,9 @@ class MultiLevelMrp(models.TransientModel):
last_qty = 0.00
nbr_create += 1
if (onhand + last_qty + move.mrp_qty) < \
- mrp_product.mrp_minimum_stock or \
+ product_mrp_area.mrp_minimum_stock or \
(onhand + last_qty) < \
- mrp_product.mrp_minimum_stock:
+ product_mrp_area.mrp_minimum_stock:
if last_date is None:
last_date = datetime.date(
datetime.strptime(move.mrp_date,
@@ -568,10 +559,10 @@ class MultiLevelMrp(models.TransientModel):
if last_date is not None and last_qty != 0.00:
name = 'Grouped Demand for %d Days' % \
- (mrp_product.mrp_nbr_days, )
- qtytoorder = mrp_product.mrp_minimum_stock - onhand - last_qty
+ (product_mrp_area.mrp_nbr_days, )
+ qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
cm = self.create_move(
- mrp_product_id=mrp_product.id, mrp_date=last_date,
+ product_mrp_area_id=product_mrp_area, mrp_date=last_date,
mrp_qty=qtytoorder, name=name)
qty_ordered = cm['qty_ordered']
onhand += qty_ordered
@@ -581,30 +572,31 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _mrp_calculation(self, mrp_lowest_llc):
logger.info('START MRP CALCULATION')
- mrp_product_obj = self.env['mrp.product']
+ product_mrp_area_obj = self.env['product.mrp.area']
counter = 0
for mrp_area in self.env['mrp.area'].search([]):
llc = 0
while mrp_lowest_llc > llc:
- mrp_products = mrp_product_obj.search(
- [('mrp_llc', '=', llc),
+ product_mrp_areas = product_mrp_area_obj.search(
+ [('product_id.llc', '=', llc),
('mrp_area_id', '=', mrp_area.id)])
llc += 1
- for mrp_product in mrp_products:
+ for product_mrp_area in product_mrp_areas:
nbr_create = 0
- onhand = mrp_product.mrp_qty_available # TODO: unreserved?
- if mrp_product.mrp_nbr_days == 0:
+ onhand = product_mrp_area.qty_available
+ # TODO: unreserved?
+ if product_mrp_area.mrp_nbr_days == 0:
# todo: review ordering by date
- for move in mrp_product.mrp_move_ids:
+ for move in product_mrp_area.mrp_move_ids:
if move.mrp_action == 'none':
if (onhand + move.mrp_qty) < \
- mrp_product.mrp_minimum_stock:
+ product_mrp_area.mrp_minimum_stock:
qtytoorder = \
- mrp_product.mrp_minimum_stock - \
+ product_mrp_area.mrp_minimum_stock - \
onhand - move.mrp_qty
cm = self.create_move(
- mrp_product_id=mrp_product,
+ product_mrp_area_id=product_mrp_area,
mrp_date=move.mrp_date,
mrp_qty=qtytoorder, name=move.name)
qty_ordered = cm['qty_ordered']
@@ -615,13 +607,14 @@ class MultiLevelMrp(models.TransientModel):
else:
# TODO: review this
nbr_create = self._init_mrp_move_grouped_demand(
- nbr_create, mrp_product)
+ nbr_create, product_mrp_area)
- if onhand < mrp_product.mrp_minimum_stock and \
+ if onhand < product_mrp_area.mrp_minimum_stock and \
nbr_create == 0:
- qtytoorder = mrp_product.mrp_minimum_stock - onhand
+ qtytoorder = \
+ product_mrp_area.mrp_minimum_stock - onhand
cm = self.create_move(
- mrp_product_id=mrp_product,
+ product_mrp_area_id=product_mrp_area,
mrp_date=date.today(),
mrp_qty=qtytoorder,
name='Minimum Stock')
@@ -636,64 +629,64 @@ class MultiLevelMrp(models.TransientModel):
logger.info('END MRP CALCULATION')
@api.model
- def _get_demand_groups(self, mrp_product):
+ def _get_demand_groups(self, product_mrp_area):
query = """
SELECT mrp_date, sum(mrp_qty)
FROM mrp_move
- WHERE mrp_product_id = %(mrp_product)s
+ WHERE product_mrp_area_id = %(mrp_product)s
AND mrp_type = 'd'
GROUP BY mrp_date
"""
params = {
- 'mrp_product': mrp_product.id
+ 'mrp_product': product_mrp_area.id
}
return query, params
@api.model
- def _get_supply_groups(self, mrp_product):
+ def _get_supply_groups(self, product_mrp_area):
query = """
SELECT mrp_date, sum(mrp_qty)
FROM mrp_move
- WHERE mrp_product_id = %(mrp_product)s
+ WHERE product_mrp_area_id = %(mrp_product)s
AND mrp_type = 's'
AND mrp_action = 'none'
GROUP BY mrp_date
"""
params = {
- 'mrp_product': mrp_product.id
+ 'mrp_product': product_mrp_area.id
}
return query, params
@api.model
- def _get_supply_action_groups(self, mrp_product):
+ def _get_supply_action_groups(self, product_mrp_area):
exclude_mrp_actions = ['none', 'cancel']
query = """
SELECT mrp_date, sum(mrp_qty)
FROM mrp_move
- WHERE mrp_product_id = %(mrp_product)s
+ WHERE product_mrp_area_id = %(mrp_product)s
AND mrp_qty <> 0.0
AND mrp_type = 's'
AND mrp_action not in %(excluded_mrp_actions)s
GROUP BY mrp_date
"""
params = {
- 'mrp_product': mrp_product.id,
+ 'mrp_product': product_mrp_area.id,
'excluded_mrp_actions': tuple(exclude_mrp_actions,)
}
return query, params
@api.model
- def _init_mrp_inventory(self, mrp_product):
+ def _init_mrp_inventory(self, product_mrp_area):
mrp_move_obj = self.env['mrp.move']
# Read Demand
demand_qty_by_date = {}
- query, params = self._get_demand_groups(mrp_product)
+ query, params = self._get_demand_groups(product_mrp_area)
self.env.cr.execute(query, params)
for mrp_date, qty in self.env.cr.fetchall():
demand_qty_by_date[mrp_date] = qty
# Read Supply
supply_qty_by_date = {}
- query, params = self._get_supply_groups(mrp_product)
+ query, params = self._get_supply_groups(product_mrp_area)
self.env.cr.execute(query, params)
for mrp_date, qty in self.env.cr.fetchall():
supply_qty_by_date[mrp_date] = qty
@@ -701,19 +694,22 @@ class MultiLevelMrp(models.TransientModel):
# TODO: if we remove cancel take it into account here,
# TODO: as well as mrp_type ('r').
supply_actions_qty_by_date = {}
- query, params = self._get_supply_action_groups(mrp_product)
+ query, params = self._get_supply_action_groups(product_mrp_area)
self.env.cr.execute(query, params)
for mrp_date, qty in self.env.cr.fetchall():
supply_actions_qty_by_date[mrp_date] = qty
# Dates
mrp_dates = set(mrp_move_obj.search([
- ('mrp_product_id', '=', mrp_product.id)],
+ ('product_mrp_area_id', '=', product_mrp_area.id)],
order='mrp_date').mapped('mrp_date'))
-
- on_hand_qty = mrp_product.current_qty_available # TODO: unreserved?
+ on_hand_qty = product_mrp_area.product_id.with_context(
+ location=product_mrp_area.mrp_area_id.location_id.id
+ )._product_available()[
+ product_mrp_area.product_id.id]['qty_available']
+ # TODO: unreserved?
for mdt in sorted(mrp_dates):
mrp_inventory_data = {
- 'mrp_product_id': mrp_product.id,
+ 'product_mrp_area_id': product_mrp_area.id,
'date': mdt,
}
demand_qty = 0.0
@@ -736,35 +732,34 @@ class MultiLevelMrp(models.TransientModel):
@api.model
def _mrp_final_process(self):
logger.info('START MRP FINAL PROCESS')
- mrp_product_ids = self.env['mrp.product'].search([
- ('mrp_llc', '<', 9999),
- ('mrp_area_id', '!=', False)])
+ product_mrp_area_ids = self.env['product.mrp.area'].search([
+ ('product_id.llc', '<', 9999)])
- for mrp_product in mrp_product_ids:
+ for product_mrp_area in product_mrp_area_ids:
# Build the time-phased inventory
- self._init_mrp_inventory(mrp_product)
+ self._init_mrp_inventory(product_mrp_area)
# Complete info on mrp_move (running availability and nbr actions)
- qoh = mrp_product.mrp_qty_available
+ qoh = product_mrp_area.qty_available
moves = self.env['mrp.move'].search([
- ('mrp_product_id', '=', mrp_product.id)],
+ ('product_mrp_area_id', '=', product_mrp_area.id)],
order='mrp_date, mrp_type desc, id')
for move in moves:
qoh = qoh + move.mrp_qty
move.running_availability = qoh
-
- nbr_actions = mrp_product.mrp_move_ids.filtered(
- lambda m: m.mrp_action != 'none')
- horizon_4w = fields.Date.to_string(
- date.today() + timedelta(weeks=4))
- nbr_actions_4w = nbr_actions.filtered(
- lambda m: m.mrp_action_date < horizon_4w)
- if nbr_actions:
- mrp_product.write({
- 'nbr_mrp_actions': len(nbr_actions),
- 'nbr_mrp_actions_4w': len(nbr_actions_4w),
- })
+ # TODO: Possible clean up needed here
+ # nbr_actions = product_mrp_area.mrp_move_ids.filtered(
+ # lambda m: m.mrp_action != 'none')
+ # horizon_4w = fields.Date.to_string(
+ # date.today() + timedelta(weeks=4))
+ # nbr_actions_4w = nbr_actions.filtered(
+ # lambda m: m.mrp_action_date < horizon_4w)
+ # if nbr_actions:
+ # product_mrp_area.write({
+ # 'nbr_mrp_actions': len(nbr_actions),
+ # 'nbr_mrp_actions_4w': len(nbr_actions_4w),
+ # })
logger.info('END MRP FINAL PROCESS')
@api.multi
diff --git a/mrp_multi_level/wizards/mrp_multi_level_view.xml b/mrp_multi_level/wizards/mrp_multi_level_views.xml
similarity index 100%
rename from mrp_multi_level/wizards/mrp_multi_level_view.xml
rename to mrp_multi_level/wizards/mrp_multi_level_views.xml