summaryrefslogtreecommitdiff
path: root/addons/mrp/models
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2019-11-19 15:04:33 +0000
committerArnold Moyaux <arm@odoo.com>2019-12-27 10:00:43 +0000
commitdd76e2df97b0f424c3364b2fdb7f39aeae842cb3 (patch)
tree3bfc931a766ee65d1ab955d186dce0fc2de33997 /addons/mrp/models
parent945730ca352ce4daf83c12889df7a12f343c904d (diff)
[FIX] mrp: remove dynamic domain on production
Diffstat (limited to 'addons/mrp/models')
-rw-r--r--addons/mrp/models/mrp_bom.py2
-rw-r--r--addons/mrp/models/mrp_production.py4
-rw-r--r--addons/mrp/models/mrp_unbuild.py25
3 files changed, 25 insertions, 6 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index b75576ea255..aaec659c9d0 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -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,
diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py
index 83758b5656f..3a5694d0fd6 100644
--- a/addons/mrp/models/mrp_production.py
+++ b/addons/mrp/models/mrp_production.py
@@ -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):
diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py
index a49249fb7ca..23221ae28c7 100644
--- a/addons/mrp/models/mrp_unbuild.py
+++ b/addons/mrp/models/mrp_unbuild.py
@@ -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):