[FIX] mrp: remove dynamic domain on production

This commit is contained in:
William Henrotin
2019-12-27 10:00:43 +00:00
committed by Arnold Moyaux
parent 945730ca35
commit dd76e2df97
5 changed files with 27 additions and 6 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ class MrpBom(models.Model):
'uom.uom', 'Unit of Measure',
default=_get_default_product_uom_id, required=True,
help="Unit of Measure (Unit of Measure) is the unit of measurement for the inventory control", domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
product_uom_category_id = fields.Many2one(related='product_tmpl_id.uom_id.category_id')
sequence = fields.Integer('Sequence', help="Gives the sequence order when displaying a list of bills of material.")
routing_id = fields.Many2one(
'mrp.routing', 'Routing', check_company=True,
+2 -2
View File
@@ -73,7 +73,8 @@ class MrpProduction(models.Model):
product_uom_id = fields.Many2one(
'uom.uom', 'Product Unit of Measure',
readonly=True, required=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)]}, domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
product_uom_qty = fields.Float(string='Total Quantity', compute='_compute_product_uom_qty', store=True)
picking_type_id = fields.Many2one(
'stock.picking.type', 'Operation Type',
@@ -432,7 +433,6 @@ class MrpProduction(models.Model):
else:
self.bom_id = False
self.product_uom_id = self.product_id.uom_id.id
return {'domain': {'product_uom_id': [('category_id', '=', self.product_id.uom_id.category_id.id)]}}
@api.onchange('bom_id')
def _onchange_bom_id(self):
+22 -3
View File
@@ -44,7 +44,7 @@ class MrpUnbuild(models.Model):
required=True, states={'done': [('readonly', True)]}, check_company=True)
mo_id = fields.Many2one(
'mrp.production', 'Manufacturing Order',
domain="[('state', 'in', ['done', 'cancel']), ('company_id', '=', company_id)]",
domain="[('id', 'in', allowed_mo_ids)]",
states={'done': [('readonly', True)]}, check_company=True)
lot_id = fields.Many2one(
'stock.production.lot', 'Lot/Serial Number',
@@ -70,6 +70,27 @@ class MrpUnbuild(models.Model):
state = fields.Selection([
('draft', 'Draft'),
('done', 'Done')], string='Status', default='draft', index=True)
allowed_mo_ids = fields.One2many('mrp.production', compute='_compute_allowed_mo_ids')
@api.depends('company_id', 'product_id')
def _compute_allowed_mo_ids(self):
for unbuild in self:
if unbuild.product_id:
domain = [
('state', '=', 'done'),
('product_id', '=', unbuild.product_id.id),
('company_id', '=', unbuild.company_id.id)
]
else:
domain = [
('state', 'in', ['done', 'cancel']),
('company_id', '=', unbuild.company_id.id)
]
allowed_mos = self.env['mrp.production'].search_read(domain, ['id'])
if allowed_mos:
unbuild.allowed_mo_ids = [mo['id'] for mo in allowed_mos]
else:
unbuild.allowed_mo_ids = False
@api.onchange('company_id')
def _onchange_company_id(self):
@@ -92,8 +113,6 @@ class MrpUnbuild(models.Model):
if self.product_id:
self.bom_id = self.env['mrp.bom']._bom_find(product=self.product_id, company_id=self.company_id.id)
self.product_uom_id = self.product_id.uom_id.id
if self.company_id:
return {'domain': {'mo_id': [('state', '=', 'done'), ('product_id', '=', self.product_id.id), ('company_id', '=', self.company_id.id)]}}
@api.constrains('product_qty')
def _check_qty(self):
@@ -102,6 +102,7 @@
<div class="o_row no-gutters d-flex">
<div class="col">
<field name="product_qty" class="mr-1" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="product_uom_id" options="{'no_open':True,'no_create':True}" force_save="1" groups="uom.group_uom" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<button type="action"
name="%(mrp.action_change_production_qty)d"
+1
View File
@@ -123,6 +123,7 @@
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
<field name="location_dest_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
<field name="has_tracking" invisible="1"/>
<field name="allowed_mo_ids" invisible="1"/>
<field name="lot_id" attrs="{'invisible': [('has_tracking', '=', 'none')], 'required': [('has_tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
<field name="company_id" groups="base.group_multi_company"/>
</group>