Hello All,
I have a One2many field and three fields inside the One2many field 'name','weight' and 'price'. I want that all values for 'weight' field added from multiple rows of One2many field.
My Python and XML Code is here:
Python Code:
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 Code:
<group>
<field name="machine_weight_id" style="width:630px">
<tree editable="bottom">
<field name="pet"/>
<field name="weight"/>
<field name="price"/>
<field name="sum"/>
</tree>
</field>
</group>