[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
This commit is contained in:
Goffin Simon
2017-06-08 16:16:28 +02:00
parent 45e94ec756
commit e79eaecc46
3 changed files with 17 additions and 1 deletions
+6
View File
@@ -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
@@ -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):
@@ -85,7 +85,7 @@
<field name="lot_name" invisible="not context.get('only_create', False)"/>
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'default_product_id': parent.product_id}"/>
context="{'default_product_id': parent.product_id, 'active_pack_operation': parent.id}"/>
<field name="qty_todo" invisible="not context.get('show_reserved') or context.get('serial') or context.get('state_done')" readonly="1"/>
<field name="qty" invisible="context.get('serial')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '&lt;=', 0.99)]}" invisible="not context.get('show_reserved') or context.get('state_done')"/>