如何在Odoo10中添加One2many字段中的特定列的值
问题描述:
我在One2many字段'name','weight'和'price'内有一个One2many字段和三个字段。我想要从One2many字段的多行中添加'weight'字段的所有值。如何在Odoo10中添加One2many字段中的特定列的值
我的Python和XML代码是在这里:
Python代码:
class body_processing(models.Model):
_name = 'body.processing'
machine_weight_id = fields.One2many('machine.weight', 'machine_id', string='Weight Machine')
class machine_weight(models.Model):
_name = 'machine.weight'
@api.depends('weight','sum', 'machine_id')
def _onchange_amount_weight(self):
sum = 0.0
vals = 0.0
for line in self.machine_id:
vals = line.weight + line.sum
print"a", vals
line.sum = line.vals
print"b", line.sum
line.sum += line.weight
print"c", line.sum
machine_id = fields.Many2one('sale.pet', string='Machine Weight', ondelete='cascade', index=True,
copy=False)
pet = fields.Char()
weight = fields.Integer()
price = fields.Integer()
sum = fields.Integer('SUM', change_default = True, default= _onchange_amount_weight)
XML代码:
答
对于这个问题,我应用的另一个功能,我伸手打印每场的重量值。但是如何从每一行获取价值权重并添加该值?
我的功能是在这里:
@api.onchange('machine_weight_id')
def _onchange_amount_weight(self):
weight_obj = self.machine_weight_id
print "a:", weight_obj
for vals in weight_obj:
print"v::", vals
print "s", vals.weight
print'sum', vals.weight