Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我需要创建一个包含库存发票总值的字段,使用origin字段向右拉_Python_Openerp_Odoo 10 - Fatal编程技术网

Python 我需要创建一个包含库存发票总值的字段,使用origin字段向右拉

Python 我需要创建一个包含库存发票总值的字段,使用origin字段向右拉,python,openerp,odoo-10,Python,Openerp,Odoo 10,我想把发票的总价值带到存货中去。用原产地来提货。我试着做些别的事情,但没用。你能帮我吗? 我猜你是奥多的新手。 修复了代码中的两个问题,现在应该可以工作了:) 1) 对于ODOOV8-v10中的计算字段,您需要计算属性,而不是默认值 2) Self将作为一组记录出现,因此对其进行迭代 3) 在新的api中,我们不会从compute方法返回,而是将值赋给字段 from odoo import api, fields, models, _ from odoo.exceptions import U

我想把发票的总价值带到存货中去。用原产地来提货。我试着做些别的事情,但没用。你能帮我吗?

我猜你是奥多的新手。 修复了代码中的两个问题,现在应该可以工作了:)

1) 对于ODOOV8-v10中的计算字段,您需要计算属性,而不是默认值

2) Self将作为一组记录出现,因此对其进行迭代

3) 在新的api中,我们不会从compute方法返回,而是将值赋给字段

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())
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')