我有個問題。我創建了一個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>,)我不明白
1 回答

qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
嘗試以下代碼:
@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
添加回答
舉報
0/150
提交
取消