mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] mrp_bom_reference_selection: Fixed onchange error closes #62
This commit is contained in:
@@ -35,10 +35,11 @@ class MrpBillOfMaterialLine(models.Model):
|
||||
'product.product', required=True, string='Product')
|
||||
|
||||
@api.multi
|
||||
def onchange_product_id(self, product_id):
|
||||
def onchange_product_id(self, product_id, product_qty=0):
|
||||
product = self.env['product.product'].browse(product_id)
|
||||
|
||||
res = {'value': {}}
|
||||
res = super(MrpBillOfMaterialLine, self).onchange_product_id(
|
||||
product_id, product_qty=product_qty)
|
||||
|
||||
if not product:
|
||||
res['value']['reference_id'] = False
|
||||
@@ -49,23 +50,22 @@ class MrpBillOfMaterialLine(models.Model):
|
||||
|
||||
return res
|
||||
|
||||
@api.one
|
||||
@api.depends('product_id')
|
||||
def _get_child_bom_lines(self):
|
||||
if self.reference_id:
|
||||
self.child_line_ids = self.reference_id.bom_id.bom_line_ids.ids
|
||||
else:
|
||||
bom_obj = self.env['mrp.bom']
|
||||
bom_id = bom_obj._bom_find(
|
||||
product_tmpl_id=self.product_id.product_tmpl_id.id,
|
||||
product_id=self.product_id.id)
|
||||
self.child_line_ids = bom_id and [
|
||||
(6, 0, child_id) for child_id in
|
||||
bom_obj.browse(bom_id).bom_line_ids.ids
|
||||
] or False
|
||||
def _compute_child_bom_lines(self):
|
||||
for record in self:
|
||||
if record.reference_id:
|
||||
record.child_line_ids = record.reference_id.bom_id.bom_line_ids
|
||||
else:
|
||||
bom_obj = self.env['mrp.bom']
|
||||
bom_id = bom_obj._bom_find(
|
||||
product_tmpl_id=record.product_id.product_tmpl_id.id,
|
||||
product_id=record.product_id.id)
|
||||
record.child_line_ids = bom_id and [
|
||||
(6, 0, child_id) for child_id in
|
||||
bom_obj.browse(bom_id).bom_line_ids.ids
|
||||
] or False
|
||||
|
||||
child_line_ids = fields.One2many(
|
||||
relation='mrp.bom.line',
|
||||
compute='_get_child_bom_lines',
|
||||
string="BOM lines of the referred bom",
|
||||
relation='mrp.bom.line', compute='_compute_child_bom_lines',
|
||||
string="BoM lines of the referred BoM",
|
||||
)
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
<field name="model">mrp.bom</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='bom_line_ids']//field[@name='product_id']" position="replace">
|
||||
<field name="product_id" on_change="onchange_product_id(product_id)"/>
|
||||
<xpath expr="//field[@name='bom_line_ids']//field[@name='product_id']" position="after">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="reference_id"
|
||||
domain="[
|
||||
|
||||
Reference in New Issue
Block a user