[IMP] mrp: block creating lot from workorder/produce wizard
When registering lot or serial number for a component in a workorder, the manufacturer can create it on on the fly. We would like to give this ability a restriction depending on the picking type. This commit blocks the creating by default but leave the possibility to tick a new checkbox on the manufacturing picking type to allow the creation of lot and serial number for components inside the production process. Task : 1891864
This commit is contained in:
@@ -24,6 +24,7 @@ class MrpAbstractWorkorder(models.AbstractModel):
|
||||
('flexible', 'Flexible')],
|
||||
required=True,
|
||||
)
|
||||
use_create_components_lots = fields.Boolean(related="production_id.picking_type_id.use_create_components_lots")
|
||||
|
||||
@api.onchange('qty_producing')
|
||||
def _onchange_qty_producing(self):
|
||||
|
||||
@@ -14,6 +14,11 @@ class StockPickingType(models.Model):
|
||||
compute='_get_mo_count')
|
||||
count_mo_late = fields.Integer(string="Number of Manufacturing Orders Late",
|
||||
compute='_get_mo_count')
|
||||
use_create_components_lots = fields.Boolean(
|
||||
string="Create New Lots/Serial Numbers for Components",
|
||||
help="Allow to create new lot/serial numbers for the components",
|
||||
default=False,
|
||||
)
|
||||
|
||||
def _get_mo_count(self):
|
||||
mrp_picking_types = self.filtered(lambda picking: picking.code == 'mrp_operation')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
from odoo import fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class StockProductionLot(models.Model):
|
||||
@@ -10,3 +11,11 @@ class StockProductionLot(models.Model):
|
||||
use_next_on_work_order_id = fields.Many2one('mrp.workorder',
|
||||
string="Next Work Order to Use",
|
||||
help='Technical: used to figure out default serial number on work orders')
|
||||
|
||||
def _check_create(self):
|
||||
active_mo_id = self.env.context.get('active_mo_id')
|
||||
if active_mo_id:
|
||||
active_mo = self.env['mrp.production'].browse(active_mo_id)
|
||||
if not active_mo.picking_type_id.use_create_components_lots:
|
||||
raise UserError(_('You are not allowed to create or edit a lot or serial number for the components with the operation type "Manufacturing". To change this, go on the operation type and tick the box "Create New Lots/Serial Numbers for Components".'))
|
||||
return super(StockProductionLot, self)._check_create()
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
<tree editable="bottom" create="0" delete="0">
|
||||
<field name="product_id" string="Components"/>
|
||||
<field name="product_tracking" invisible="1"/>
|
||||
<field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}"/>
|
||||
<field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id, 'active_mo_id': parent.production_id}"/>
|
||||
<field name="qty_to_consume" readonly="1"/>
|
||||
<field name="qty_reserved" readonly="1"/>
|
||||
<field name="qty_done" string="Done"/>
|
||||
|
||||
@@ -106,6 +106,11 @@
|
||||
<field name="show_reserved" position="attributes">
|
||||
<attribute name="attrs">{"invisible": [("code", "=", "mrp_operation")]}</attribute>
|
||||
</field>
|
||||
<xpath expr="//group[@name='stock_picking_type_lot']" position="after">
|
||||
<group attrs='{"invisible": [("code", "!=", "mrp_operation")]}' string="Traceability" groups="stock.group_production_lot">
|
||||
<field name="use_create_components_lots"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<tree editable="top" delete="0" decoration-danger="(qty_to_consume < qty_done)">
|
||||
<field name="product_id" attrs="{'readonly': [('move_id', '!=', False)]}" required="1" domain="[('id', '!=', parent.product_id)]" force_save="1"/>
|
||||
<field name="product_tracking" invisible="1"/>
|
||||
<field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_product_id': product_id}" domain="[('product_id', '=', product_id)]" groups="stock.group_production_lot"/>
|
||||
<field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_product_id': product_id, 'active_mo_id': parent.production_id}" domain="[('product_id', '=', product_id)]" groups="stock.group_production_lot"/>
|
||||
<field name="qty_to_consume" readonly="1" force_save="1"/>
|
||||
<field name="qty_reserved" readonly="1" force_save="1"/>
|
||||
<field name="qty_done"/>
|
||||
|
||||
@@ -28,13 +28,16 @@ class ProductionLot(models.Model):
|
||||
('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'),
|
||||
]
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
def _check_create(self):
|
||||
active_picking_id = self.env.context.get('active_picking_id', False)
|
||||
if active_picking_id:
|
||||
picking_id = self.env['stock.picking'].browse(active_picking_id)
|
||||
if picking_id and not picking_id.picking_type_id.use_create_lots:
|
||||
raise UserError(_('You are not allowed to create a lot or serial number with this operation type. To change this, go on the operation type and tick the box "Create New Lots/Serial Numbers".'))
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
self._check_create()
|
||||
return super(ProductionLot, self).create(vals_list)
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<group attrs='{"invisible": [("code", "not in", ["incoming", "outgoing", "internal"])]}' string="Traceability" groups="stock.group_production_lot">
|
||||
<group attrs='{"invisible": [("code", "not in", ["incoming", "outgoing", "internal"])]}' string="Traceability" groups="stock.group_production_lot" name="stock_picking_type_lot">
|
||||
<field name="use_create_lots"/>
|
||||
<field name="use_existing_lots"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user