[FIX] mrp: display warning when archiving component product

Steps to reproduce the bug:
- Create a BoM with components
- Archive one of the components

Problem:
No warning is displayed for the user to inform that the product is
used as a component in a BoM

opw-3089104

closes odoo/odoo#107863

X-original-commit: 9b7c416387d93507b6f750aba58ad6233a59d512
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-12-13 18:09:51 +01:00
parent fead26df53
commit 3ac47d27f5
2 changed files with 43 additions and 1 deletions
+8
View File
@@ -3139,6 +3139,14 @@ msgstr ""
msgid "Note that components"
msgstr ""
#. module: mrp
#: code:addons/mrp/models/product.py:0 code:addons/mrp/models/product.py:0
#, python-format
msgid ""
"Note that product(s): '%s' is/are still linked to active Bill of Materials, "
"which means that the product can still be used on it/them."
msgstr ""
#. module: mrp
#: model:ir.model.fields,field_description:mrp.field_mrp_bom__message_needaction_counter
#: model:ir.model.fields,field_description:mrp.field_mrp_production__message_needaction_counter
+35 -1
View File
@@ -4,7 +4,7 @@
from datetime import timedelta
from itertools import groupby
import operator as py_operator
from odoo import api, fields, models
from odoo import fields, models, _
from odoo.tools import groupby
from odoo.tools.float_utils import float_round, float_is_zero
@@ -92,6 +92,23 @@ class ProductTemplate(models.Model):
if templates:
return templates.mapped('product_variant_id').action_compute_bom_days()
def action_archive(self):
filtered_products = self.env['mrp.bom.line'].search([('product_id', 'in', self.product_variant_ids.ids)]).product_id.mapped('display_name')
res = super().action_archive()
if filtered_products:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _("Note that product(s): '%s' is/are still linked to active Bill of Materials, "
"which means that the product can still be used on it/them.", filtered_products),
'type': 'warning',
'sticky': True, #True/False will display for few seconds if false
'next': {'type': 'ir.actions.act_window_close'},
},
}
return res
class ProductProduct(models.Model):
_inherit = "product.product"
@@ -333,3 +350,20 @@ class ProductProduct(models.Model):
if OPERATORS[operator](product.qty_available, value):
product_ids.append(product.id)
return list(set(product_ids))
def action_archive(self):
filtered_products = self.env['mrp.bom.line'].search([('product_id', 'in', self.ids)]).product_id.mapped('display_name')
res = super().action_archive()
if filtered_products:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _("Note that product(s): '%s' is/are still linked to active Bill of Materials, "
"which means that the product can still be used on it/them.", filtered_products),
'type': 'warning',
'sticky': True, #True/False will display for few seconds if false
'next': {'type': 'ir.actions.act_window_close'},
},
}
return res