0
votes

I have a question. I created a one2many which is a replica of a one2many budget field of the sales module.

Well I want to obey the summation of all the values ​​of the field that is inside the one2many

example :

This is my one2many:

order_line = fields.One2many ('sale.order.line', 'order_id', string = 'Orders', copy = True)

at visual level is this: enter image description here

I want the subtotal sum so that after getting the total amount put it where it says (total :), so far I have echoed this but the behavior is not appropriate:

 @api.multi
    @api.depends('order_line.price_unit')
    def _total(self):
        total = 0
        for element in self.order_line:
            total = total + element.prince_unit
        self.total = total

finally, it does not show me anything in the total field and if I print self.order_line it shows me the following:

sale.order (<odoo.models.NewId object at 0x000000000A9CD630>,)

and I do not understand

1

1 Answers

0
votes

Try with following code:

@api.multi
@api.depends('order_line.price_unit')
def _total(self):
    for order in self:
        total = 0
        for element in order.order_line:
            total += element.price_unit
        order.total = total