Reputation: 1531
In 'products.template' table I created three fields width,length and gsm. Now I want to retrieve it in 'mrp' table.First I will get the ids from mrp bill of materials and assign it to a variable called prod. 'mrp.bom.line' table contains product id.So through iterator I want to pass id of product stored in mrp bill of materials table to retrieve the value of width,length and gsm stored in product.template table.I am getting error as programming error can't adapt type 'product.product'
.
@api.multi
def _compute_rim_weight(self):
bill_of_materials_id=[1,2,3]
prod = self.env['mrp.bom.line'].browse(bill_of_materials_id)
for i in prod:
j = self.env['product.template'].browse(i.product_id)
self.rim_weight = (j.width * j.length * j.gsm)/20000
return self.rim_weight
Upvotes: 0
Views: 2257
Reputation: 2594
In ODOO browse take id not object
so just replace browse(i.product_id) with browse(i.product_id.id) as below:
j = self.env['product.template'].browse(i.product_id.id)
One more thing if in case product.template
have** many2one relation** with model :mrp.bom.line
from my understanding you even don't need the call browse .
Directly call line.product_id.width ,line.product_id.length,line.product_id.gsm as below :
@api.multi
def _compute_rim_weight(self):
bill_of_materials_ids=[1,2,3]
bom_lines = self.env['mrp.bom.line'].browse(bill_of_materials_ids)
for line in bom_lines:
self.rim_weight = (line.product_id.width * line.product_id.length * line.product_id.gsm)/20000
return self.rim_weight
@api.one
def _compute_rim_weight(self):
rim_weight =0
for line in self.bom_id.bom_line_ids:
rim_weight+ = (line.product_id.width * line.product_id.length * line.product_id.gsm)/20000
self.rim_weight =rim_weight
Upvotes: 2