【问题标题】:Loop through record lines method - Odoo v8循环记录线方法 - Odoo v8
【发布时间】:2017-11-15 20:38:03
【问题描述】:

我有这个方法:

@api.onchange('qty', 'consumed_qty')
def _remaining_func(self):
    for qty in self.isbn:
        if self.qty or self.consumed_qty:
            self.remaining_qty = self.qty +(-self.consumed_qty)

但是我需要它来循环遍历我的行(One2many 字段)的记录,现在,如果我只添加一条记录,它工作得很好,但如果我添加两条或更多,它会抛出 Expected singleton 错误。

那么,我怎样才能用这个方法循环呢?

我添加了for qty in self.isbn,但没有成功。

这是声明此方法的类:

class bsi_production_order_lines(models.Model):
    _name = 'bsi.production.order.lines'

    production_order = fields.Many2one('bsi.production.order', string="Production Orders")
    isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
    qty = fields.Float(string="Quantity")
    consumed_qty = fields.Float(string="Consumed quantity")
    remaining_qty = fields.Float(string="Remaining quantity", compute="_remaining_func")

有什么想法吗?

【问题讨论】:

    标签: python openerp odoo-8


    【解决方案1】:

    你可以试试:

    @api.onchange('qty', 'consumed_qty')
    def _remaining_func(self):
        for s in self:
            for qty in s.isbn:
                if s.qty or s.consumed_qty:
                    s.remaining_qty = s.qty +(-s.consumed_qty)
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 2021-05-05
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多