[FIX] mrp: error w/o traceback on create BoM

If a Bill of Material is created without code (eg. when created as a new
group from a kanban view grouped by BoM) we would get a traceback
instead of an error.

With this changeset, we get a "You cannot create a new Bill of Material
from here." error if it is being tried.

opw-2124162
fix #38904
closes #40289

closes odoo/odoo#40457

X-original-commit: 32c13cd7d1387c0ea81a9bb5968d18c2b8f32051
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
fw-bot
2019-11-18 19:28:01 +00:00
parent b0b5fa6ec9
commit abd9d1506e
2 changed files with 13 additions and 0 deletions
+6
View File
@@ -4711,6 +4711,12 @@ msgid ""
"numbers encoded."
msgstr ""
#. module: mrp
#: code:addons/mrp/models/mrp_bom.py:0
#, python-format
msgid "You cannot create a new Bill of Material from here."
msgstr ""
#. module: mrp
#: code:addons/mrp/models/mrp_unbuild.py:0
#, python-format
+7
View File
@@ -121,6 +121,13 @@ class MrpBom(models.Model):
for line in self.bom_line_ids:
line.operation_id = False
@api.model
def name_create(self, name):
# prevent to use string as product_tmpl_id
if isinstance(name, str):
raise UserError(_("You cannot create a new Bill of Material from here."))
return super(MrpBom, self).name_create(name)
def name_get(self):
return [(bom.id, '%s%s' % (bom.code and '%s: ' % bom.code or '', bom.product_tmpl_id.display_name)) for bom in self]