Openerp 如何在self.env odoo中传递id?

Openerp 如何在self.env odoo中传递id?,openerp,odoo-8,Openerp,Odoo 8,在“products.template”表中,我创建了三个字段:宽度、长度和gsm。现在我想在“mrp”表中检索它。首先,我将从mrp bom表中获取id,并将其分配给一个名为prod的变量。“mrp.bom.line”表包含产品id。因此,我想通过迭代器传递存储在mrp bom表中的产品id,以检索宽度值,长度和gsm存储在product.template表中。由于编程错误无法适应'product.product'类型,我收到了错误。 @api.multi def _compute_rim_w

在“products.template”表中,我创建了三个字段:宽度、长度和gsm。现在我想在“mrp”表中检索它。首先,我将从mrp bom表中获取id,并将其分配给一个名为prod的变量。“mrp.bom.line”表包含产品id。因此,我想通过迭代器传递存储在mrp bom表中的产品id,以检索宽度值,长度和gsm存储在product.template表中。由于
编程错误无法适应'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
在ODOO浏览中,获取id对象

因此,只需将浏览(i.产品标识)替换为浏览(i.产品标识),如下所示:

j = self.env['product.template'].browse(i.product_id.id)
如果
product.template
模型有**多个关系**:mrp.bom.line
,我认为您甚至不需要调用browse

直接调用line.product\u id.widthline.product\u id.lengthline.product\u id.gsm,如下所示:

@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
在ODOO浏览中,获取id对象

因此,只需将浏览(i.产品标识)替换为浏览(i.产品标识),如下所示:

j = self.env['product.template'].browse(i.product_id.id)
如果
product.template
模型有**多个关系**:mrp.bom.line
,我认为您甚至不需要调用browse

直接调用line.product\u id.widthline.product\u id.lengthline.product\u id.gsm,如下所示:

@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

在第一行中,我正在硬编码物料清单id如何使用self.env实现自动化。我想将BOM id传递到此函数的第二行\u compute\u rim\u weight weight In mrp.BOM.line??如果是,则只使用“for line in self”而不是“weight”,我想将BOM id(1,2,3)传递到第二行。对于id 1,产品id为4,所以browse()方法接受id,所以我想避免硬编码BOM id(1,2,3)并将其传递给browse()由于用@pi.multi修饰的_compute\u rim\u weight id,所以如果_compute\u rim\u weight weight在mrp.bom.line中,我们不需要使用browse,我们只需迭代self,因为self还包含模型的对象列表(如果该方法用@api.multi修饰),希望你得到我想要说的结果,只需确认我的方法compute\u rim\u weight weight在模型mrp.bom.line中在第一行我正在硬编码bom id如何使用self.env实现自动化。我想将bom id传递到此函数的第二行\u compute\u rim\u weight weight在mrp.bom.line中??如果是,则只使用“for line in self”而不是“weight”,我想将BOM id(1,2,3)传递到第二行。对于id 1,产品id为4,所以browse()方法接受id,所以我想避免硬编码BOM id(1,2,3)并将其传递给browse()由于用@pi.multi修饰的_compute\u rim\u weight id,所以如果_compute\u rim\u weight weight在mrp.bom.line中,我们不需要使用browse,我们只需迭代self,因为self还包含模型的对象列表(如果该方法用@api.multi修饰),希望你得到我想要说的结果,请确认我的方法计算重量在模型mrp.bom.line中