One2Many 在 Odoo 中获得价值

One2Many get value in Odoo

我有一个问题。我创建了一个 one2many,它是销售模块的 one2many 预算字段的副本。

嗯我要服从one2many里面的字段所有值的求和

示例:

这是我的 one2many:

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

在视觉层面是这样的:

我想要小计总和,以便在得到总金额后把它放在它说的地方(总计:),到目前为止我已经回应了这个但是行为不合适:

 @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

最后,它没有在总字段中显示任何内容,如果我打印 self.order_line,它会显示以下内容:

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

我不明白

尝试使用以下代码:

@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