From e79eaecc46d72187c8a7ad39c0f2b17b61dff267 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 8 Jun 2017 15:37:55 +0200 Subject: [PATCH] [FIX] stock:Creating new lots when option "use only existing lots" is activated When the field use_create_lots is set to False in a picking type, it is not possible to create lot for a pack operation linked to this picking type. opw:744862 --- addons/stock/i18n/stock.pot | 6 ++++++ addons/stock/models/stock_production_lot.py | 10 ++++++++++ addons/stock/views/stock_pack_operation_views.xml | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index e01b6291165..c257035f4a9 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -6596,6 +6596,12 @@ msgid "You cannot set a negative product quantity in an inventory line:\n" " %s - qty: %s" msgstr "" +#. module: stock +#: code:addons/stock/models/stock_production_lot.py:37 +#, python-format +msgid "You are not allowed to create a lot for this picking type" +msgstr "" + #. module: stock #: code:addons/stock/models/stock_move.py:919 #, python-format diff --git a/addons/stock/models/stock_production_lot.py b/addons/stock/models/stock_production_lot.py index 60f370fff51..a568cd80fe3 100644 --- a/addons/stock/models/stock_production_lot.py +++ b/addons/stock/models/stock_production_lot.py @@ -2,6 +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 class ProductionLot(models.Model): @@ -27,6 +28,15 @@ class ProductionLot(models.Model): ('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'), ] + @api.model + def create(self, vals): + pack_id = self.env.context.get('active_pack_operation', False) + if pack_id: + pack = self.env['stock.pack.operation'].browse(pack_id) + if pack.picking_id and not pack.picking_id.picking_type_id.use_create_lots: + raise UserError(_("You are not allowed to create a lot for this picking type")) + return super(ProductionLot, self).create(vals) + @api.one @api.depends('quant_ids.qty') def _product_qty(self): diff --git a/addons/stock/views/stock_pack_operation_views.xml b/addons/stock/views/stock_pack_operation_views.xml index 5b6919dab83..cd8469d4672 100644 --- a/addons/stock/views/stock_pack_operation_views.xml +++ b/addons/stock/views/stock_pack_operation_views.xml @@ -85,7 +85,7 @@ + context="{'default_product_id': parent.product_id, 'active_pack_operation': parent.id}"/>