From 4fad5bd0ca8b85eef3d7984dc05c06a6103b7b09 Mon Sep 17 00:00:00 2001 From: "Pieter Claeys (clpi)" Date: Fri, 8 Apr 2022 14:30:25 +0000 Subject: [PATCH] [IMP] stock: disable scrap locations for manufacturing operation types Task: 2799674 Community PR: https://github.com/odoo/odoo/pull/88801 Part-of: odoo/odoo#88801 --- addons/stock/models/stock_location.py | 8 +++++++- addons/stock/models/stock_picking.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index 5c51a59c7c5..9ae9013d7cb 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -7,7 +7,7 @@ from collections import defaultdict, OrderedDict from datetime import timedelta from odoo import _, api, fields, models -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from odoo.osv import expression from odoo.tools.float_utils import float_compare @@ -167,6 +167,12 @@ class Location(models.Model): if self.usage not in ('internal', 'inventory'): self.scrap_location = False + @api.constrains('scrap_location') + def _check_scrap_location(self): + for record in self: + if record.scrap_location and self.env['stock.picking.type'].search([('code', '=', 'mrp_operation'), ('default_location_dest_id', '=', record.id)]): + raise ValidationError(_("You cannot set a location as a scrap location when it assigned as a destination location for a manufacturing type operation.")) + def write(self, values): if 'company_id' in values: for location in self: diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index bd303301368..6c4524e59a0 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -9,7 +9,7 @@ from collections import defaultdict from odoo import SUPERUSER_ID, _, api, fields, models from odoo.addons.stock.models.stock_move import PROCUREMENT_PRIORITIES -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from odoo.osv import expression from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, format_datetime, format_date, groupby from odoo.tools.float_utils import float_compare, float_is_zero, float_round @@ -204,6 +204,12 @@ class PickingType(models.Model): if self.show_operations and self.code != 'incoming': self.show_reserved = True + @api.constrains('default_location_dest_id') + def _check_default_location(self): + for record in self: + if record.code == 'mrp_operation' and record.default_location_dest_id.scrap_location: + raise ValidationError(_("You cannot set a scrap location as the destination location for a manufacturing type operation.")) + def _get_action(self, action_xmlid): action = self.env["ir.actions.actions"]._for_xml_id(action_xmlid) if self: