[FIX] mrp: prevent creation of reordering rule on kit
Because kits might never be in stock, it's impossible to fullfil the quantity of a reordering rule: asking a mini/maxi quantity on a kit makes no sense. Odoo will continuously propose to order more to reach the quantity necessary for the kit, but will never reach the asked qty, as it's a kit, not a manufactured product. OPW-2448878 closes odoo/odoo#68362 X-original-commit: c47a9319c081105e46e56f881b25fd6442266089 Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
@@ -360,6 +360,13 @@ msgstr ""
|
||||
msgid "A Manufacturing Order is already done or cancelled."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: code:addons/mrp/models/stock_warehouse.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"A product with a kit-type bill of materials can not have a reordering rule."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: model:ir.model.fields,field_description:mrp.field_mrp_document__access_token
|
||||
msgid "Access Token"
|
||||
@@ -4795,6 +4802,14 @@ msgid ""
|
||||
"link to your file."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: code:addons/mrp/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You can not create a kit-type bill of materials for products that have at "
|
||||
"least one reordering rule."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: code:addons/mrp/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
|
||||
@@ -145,6 +145,13 @@ class MrpBom(models.Model):
|
||||
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]
|
||||
|
||||
@api.constrains('product_tmpl_id', 'product_id', 'type')
|
||||
def check_kit_has_not_orderpoint(self):
|
||||
product_ids = [pid for bom in self.filtered(lambda bom: bom.type == "phantom")
|
||||
for pid in (bom.product_id.ids or bom.product_tmpl_id.product_variant_ids.ids)]
|
||||
if self.env['stock.warehouse.orderpoint'].search([('product_id', 'in', product_ids)], count=True):
|
||||
raise ValidationError(_("You can not create a kit-type bill of materials for products that have at least one reordering rule."))
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_running_mo(self):
|
||||
if self.env['mrp.production'].search([('bom_id', 'in', self.ids), ('state', 'not in', ['done', 'cancel'])], limit=1):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
class StockWarehouse(models.Model):
|
||||
@@ -296,3 +296,13 @@ class StockWarehouse(models.Model):
|
||||
if warehouse.manufacture_pull_id and name:
|
||||
warehouse.manufacture_pull_id.write({'name': warehouse.manufacture_pull_id.name.replace(warehouse.name, name, 1)})
|
||||
return res
|
||||
|
||||
class Orderpoint(models.Model):
|
||||
_inherit = "stock.warehouse.orderpoint"
|
||||
|
||||
@api.constrains('product_id')
|
||||
def check_product_is_not_kit(self):
|
||||
if self.env['mrp.bom'].search(['|', ('product_id', 'in', self.product_id.ids),
|
||||
'&', ('product_id', '=', False), ('product_tmpl_id', 'in', self.product_id.product_tmpl_id.ids),
|
||||
('type', '=', 'phantom')], count=True):
|
||||
raise ValidationError(_("A product with a kit-type bill of materials can not have a reordering rule."))
|
||||
|
||||
Reference in New Issue
Block a user