我有這種方法,它應該循環在One2many
對象,但實際循環不工作,我的意思是,如果我只添加一條線,它工作正常,但如果我添加多行,比它拋出我的singleton
錯誤:ValueError:期望的單身人士: - Odoo v8
@api.multi
@api.depends('order_lines', 'order_lines.isbn')
def checkit(self):
for record in self:
if self.order_lines.isbn:
return self.order_lines.isbn
else:
raise Warning(('Enter at least 1 ISBN to produce'))
這些都是此方法是基於兩個對象:
class bsi_production_order(models.Model):
_name = 'bsi.production.order'
name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
date = fields.Date(string="Production Date")
production_type = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True,
track_visibility='onchange', copy=False,
help=" ")
notes = fields.Text(string="Notes")
order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="Order lines", copy=True)
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.Integer(string="Quantity")
consumed_qty = fields.Float(string="Consumed quantity")
remaining_qty = fields.Float(string="Remaining quantity", compute="_remaining_func")
@api.onchange('qty', 'consumed_qty')
def _remaining_func(self):
if self.consumed_qty or self.qty:
self.remaining_qty = self.consumed_qty - self.qty
如果我添加多個isbn
上bsi.production.order.lines
它拋出我:
ValueError
Expected singleton: bsi.production.order.lines(10, 11)
任何想法?
編輯
重複的是另一種情況,實際上我已經改變了我的方法來匹配一個在其他問題中詳細說明,但沒有成功。所以這不是真的,或者至少不是一個只有api的問題。
可能重複[ValueError Expected singleton,Odoo8](https://stackoverflow.com/questions/31070640/valueerror-expected-singleton-odoo8) –