diff --git a/addons/mrp/wizard/__init__.py b/addons/mrp/wizard/__init__.py
index 5047d85ede2..466142a28a5 100644
--- a/addons/mrp/wizard/__init__.py
+++ b/addons/mrp/wizard/__init__.py
@@ -4,3 +4,4 @@
from . import change_production_qty
from . import stock_warn_insufficient_qty
from . import mrp_production_backorder
+from . import mrp_consumption_warning
diff --git a/addons/mrp/wizard/mrp_consumption_warning.py b/addons/mrp/wizard/mrp_consumption_warning.py
new file mode 100644
index 00000000000..3ad16839cf8
--- /dev/null
+++ b/addons/mrp/wizard/mrp_consumption_warning.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api
+
+
+class MrpConsumptionWarning(models.TransientModel):
+ _name = 'mrp.consumption.warning'
+ _description = "Wizard in case of consumption in warning/strict and more component has been used for a MO (related to the bom)"
+
+ mrp_production_ids = fields.Many2many('mrp.production')
+ mrp_production_count = fields.Integer(compute="_compute_mrp_production_count")
+
+ consumption = fields.Selection([
+ ('flexible', 'Allowed'),
+ ('warning', 'Allowed with warning'),
+ ('strict', 'Blocked')], compute="_compute_consumption")
+ mrp_consumption_warning_line_ids = fields.One2many('mrp.consumption.warning.line', 'mrp_consumption_warning_id')
+
+ @api.depends("mrp_production_ids")
+ def _compute_mrp_production_count(self):
+ for wizard in self:
+ wizard.mrp_production_count = len(wizard.mrp_production_ids)
+
+ @api.depends("mrp_consumption_warning_line_ids.consumption")
+ def _compute_consumption(self):
+ for wizard in self:
+ consumption_map = set(wizard.mrp_consumption_warning_line_ids.mapped("consumption"))
+ wizard.consumption = "strict" in consumption_map and "strict" or "warning" in consumption_map and "warning" or "flexible"
+
+ def action_confirm(self):
+ return self.mrp_production_ids.with_context(skip_consumption=True).button_mark_done()
+
+
+class MrpConsumptionWarningLine(models.TransientModel):
+ _name = 'mrp.consumption.warning.line'
+ _description = "Line of issue consumption"
+
+ mrp_consumption_warning_id = fields.Many2one('mrp.consumption.warning', "Parent Wizard", readonly=True, required=True, ondelete="cascade")
+ mrp_production_id = fields.Many2one('mrp.production', "Manufacturing Order", readonly=True, required=True, ondelete="cascade")
+ consumption = fields.Selection(related="mrp_production_id.consumption")
+
+ product_id = fields.Many2one('product.product', "Product", readonly=True, required=True)
+ product_uom_id = fields.Many2one('uom.uom', "Unit of Measure", related="product_id.uom_id", readonly=True)
+ product_consumed_qty_uom = fields.Float("Consumed", readonly=True)
+ product_expected_qty_uom = fields.Float("To Consume", readonly=True)
diff --git a/addons/mrp/wizard/mrp_consumption_warning_views.xml b/addons/mrp/wizard/mrp_consumption_warning_views.xml
new file mode 100644
index 00000000000..947fccdac47
--- /dev/null
+++ b/addons/mrp/wizard/mrp_consumption_warning_views.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+ Consumption Warning
+ mrp.consumption.warning
+
+
+
+
+
+
+ Consumption Warning
+ ir.actions.act_window
+ mrp.consumption.warning
+ form
+ new
+
+
+
+
diff --git a/addons/mrp_account/models/mrp_production.py b/addons/mrp_account/models/mrp_production.py
index 3a10fdacf1f..4bd0c337594 100644
--- a/addons/mrp_account/models/mrp_production.py
+++ b/addons/mrp_account/models/mrp_production.py
@@ -71,7 +71,6 @@ class MrpProduction(models.Model):
AccountAnalyticLine.create(vals)
def button_mark_done(self):
- self.ensure_one()
res = super(MrpProduction, self).button_mark_done()
for order in self:
order._costs_generate()
diff --git a/addons/mrp_account/tests/test_mrp_account.py b/addons/mrp_account/tests/test_mrp_account.py
index bd9adba0a5c..f77dbfc3c6e 100644
--- a/addons/mrp_account/tests/test_mrp_account.py
+++ b/addons/mrp_account/tests/test_mrp_account.py
@@ -78,7 +78,7 @@ class TestMrpAccount(TestWorkOrderProcessCommon):
mo_form = Form(production_table)
mo_form.qty_producing = 1
production_table = mo_form.save()
- production_table.post_inventory()
+ production_table._post_inventory()
move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").stock_valuation_layer_ids.value
# 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost)
diff --git a/addons/mrp_account/tests/test_valuation_layers.py b/addons/mrp_account/tests/test_valuation_layers.py
index a116995a0c4..df03cc163de 100644
--- a/addons/mrp_account/tests/test_valuation_layers.py
+++ b/addons/mrp_account/tests/test_valuation_layers.py
@@ -55,7 +55,10 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._make_in_move(self.component, 1, 20)
mo = self._make_mo(self.bom, 2)
self._produce(mo, 1)
- mo.post_inventory()
+ action = mo.button_mark_done()
+ backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
+ backorder.save().action_backorder()
+ mo = mo.procurement_group_id.mrp_production_ids[-1]
self.assertEqual(self.component.value_svl, 20)
self.assertEqual(self.product1.value_svl, 10)
self.assertEqual(self.component.quantity_svl, 1)
@@ -93,7 +96,7 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._produce(mo, 1)
action = mo.button_mark_done()
backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
- backorder.save().action_close_mo()
+ backorder.save().action_backorder()
mo = mo.procurement_group_id.mrp_production_ids[-1]
self.assertEqual(self.component.value_svl, 20)
self.assertEqual(self.product1.value_svl, 10)
@@ -131,7 +134,7 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._make_in_move(self.component, 1, 20)
mo = self._make_mo(self.bom, 2)
self._produce(mo, 1)
- mo.post_inventory()
+ mo._post_inventory()
self.assertEqual(self.component.value_svl, 20)
self.assertEqual(self.product1.value_svl, 8.8)
self.assertEqual(self.component.quantity_svl, 1)
@@ -169,7 +172,7 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._make_in_move(self.component, 1)
mo = self._make_mo(self.bom, 2)
self._produce(mo, 1)
- mo.post_inventory()
+ mo._post_inventory()
self.assertEqual(self.component.value_svl, 8.8)
self.assertEqual(self.product1.value_svl, 8.8)
self.assertEqual(self.component.quantity_svl, 1)
@@ -208,7 +211,7 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._make_in_move(self.component, 1)
mo = self._make_mo(self.bom, 2)
self._produce(mo, 1)
- mo.post_inventory()
+ mo._post_inventory()
self.assertEqual(self.component.value_svl, 8.8)
self.assertEqual(self.product1.value_svl, 7.2)
self.assertEqual(self.component.quantity_svl, 1)
@@ -246,7 +249,7 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self._make_in_move(self.component, 1, 20)
mo = self._make_mo(self.bom, 2)
self._produce(mo, 1)
- mo.post_inventory()
+ mo._post_inventory()
self.assertEqual(self.component.value_svl, 15)
self.assertEqual(self.product1.value_svl, 15)
self.assertEqual(self.component.quantity_svl, 1)
diff --git a/addons/mrp_product_expiry/tests/test_mrp_product_expiry.py b/addons/mrp_product_expiry/tests/test_mrp_product_expiry.py
index ac0f2f3528a..22e9764d2fd 100644
--- a/addons/mrp_product_expiry/tests/test_mrp_product_expiry.py
+++ b/addons/mrp_product_expiry/tests/test_mrp_product_expiry.py
@@ -49,6 +49,7 @@ class TestStockProductionLot(TestStockCommon):
'product_tmpl_id': cls.product_apple_pie.product_tmpl_id.id,
'product_uom_id': cls.uom_unit.id,
'product_qty': 1.0,
+ 'consumption': 'flexible',
'type': 'normal',
'bom_line_ids': [
(0, 0, {'product_id': cls.product_apple.id, 'product_qty': 3}),
diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py
index 0ab1655a6dc..43cba77b1a3 100644
--- a/addons/mrp_subcontracting/models/stock_picking.py
+++ b/addons/mrp_subcontracting/models/stock_picking.py
@@ -83,7 +83,7 @@ class StockPicking(models.Model):
productions |= production
for subcontracted_production in productions:
if subcontracted_production.state == 'progress':
- subcontracted_production.post_inventory()
+ subcontracted_production._post_inventory()
else:
subcontracted_production.button_mark_done()
# For concistency, set the date on production move before the date
diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py
index 71bc229c6e2..527e992faf7 100644
--- a/addons/sale_mrp/tests/test_sale_mrp_flow.py
+++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py
@@ -434,7 +434,7 @@ class TestSaleMrpFlow(AccountTestCommon):
mo_form = Form(mnf_product_d)
mo_form.qty_producing = 20
mnf_product_d = mo_form.save()
- mnf_product_d.post_inventory()
+ mnf_product_d._post_inventory()
# Check state of manufacturing order.
self.assertEqual(mnf_product_d.state, 'done', 'Manufacturing order should still be in progress state.')
@@ -484,7 +484,7 @@ class TestSaleMrpFlow(AccountTestCommon):
mo_form = Form(mnf_product_a)
mo_form.qty_producing = mo_form.product_qty
mnf_product_a = mo_form.save()
- mnf_product_a.post_inventory()
+ mnf_product_a._post_inventory()
# Check state of manufacturing order product A.
self.assertEqual(mnf_product_a.state, 'done', 'Manufacturing order should still be in the progress state.')
# Check product A avaialble quantity should be 120.