我想把发票的总价值带到stock.picking使用原点使其正确我试图做别的事情,它没有用,你能帮帮我吗?
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = 'stock.picking'
def get_x_total(self):
current_total = self.env['account.invoice'].search([('origin','=',self.origin)])
x_total = current_total.('account.invoice').amount_total
return x_total
x_amout_total = fields.Float('Valor Total', default=lambda self: self.get_x_total())
答案 0 :(得分:0)
猜猜你是odoo的新手。 现在应该在你的代码中解决几件问题:)
1)你需要为odoo v8-v10
中的计算字段计算属性而不是默认值2)自我将作为一组记录出现,所以迭代它
3)在新的api中,我们不从计算方法返回只是将值赋给字段
from odoo import api, fields, models
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.multi
@api.depends('origin')
def get_x_total(self):
for rec in self:
invoice_rec = self.env['account.invoice'].search([('origin','=',rec.origin)], limit=1)
rec.x_amout_total = invoice_rec.amount_total or 0.0 #in case no origin default value
x_amout_total = fields.Float('Valor Total', compute='get_x_total')