Manish Bohra
Manish Bohra

Reputation: 340

How to add values of particular field from One2many field in Odoo

I have a One2many field and three fields inside the One2many field 'name','id' and 'price'. I want that all values for 'price' field added from multiple rows of One2many field.

My Python function here:

    @api.onchange('price', 'vals', 'sum')
    def _onchange_amount_weight(self):
    if self.price:
        sum = 0;
        print "s", sum
        self.vals = self.price + self.sum
        print"a", self.vals
        self.sum = self.vals
        print"b", self.sum
        self.sum += self.price
        print"c", self.sum

Thanks...

Upvotes: 1

Views: 733

Answers (1)

Karara Mohamed
Karara Mohamed

Reputation: 933

you can do that by adding this code in XML view Tree

 <field name="price" sum="Total price" widget="monetary"/> 
 <field name="vals" sum="Total vals" widget="monetary"/> 
 <field name="sum" sum="Total sum" widget="monetary"/> 

Upvotes: 1

Related Questions