ValueError:预期的单身人士:-Odoo v8 [英] ValueError: Expected singleton: - Odoo v8

查看:66
本文介绍了ValueError:预期的单身人士:-Odoo v8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个方法,它应该在 One2many 对象上循环,但实际循环不起作用,我的意思是,如果我只添加一行它工作正常,但如果我添加更多比一行,比它抛出我 singleton 错误:

@api.multi@api.depends('order_lines', 'order_lines.isbn')def checkit(自我):自我记录:如果 self.order_lines.isbn:返回 self.order_lines.isbn别的:raise Warning(('输入 至少 1 个ISBN以生产'))

这是该方法所基于的两个对象:

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="生产日期")生产类型 = fields.Selection([('预算','预算'),('非预算','非预算'),('直接','直接订单'),], string='订单类型', index=True,track_visibility='onchange', copy=False,帮助="")notes = fields.Text(string="Notes")order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="订单行", copy=True)类 bsi_production_order_lines(models.Model):_name = 'bsi.production.order.lines'production_order = fields.Many2one('bsi.production.order', string="生产订单")isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")qty = fields.Integer(string="Quantity")消费数量 = fields.Float(string="消费数量")剩余数量 = fields.Float(string="剩余数量", compute="_remaining_func")@api.onchange('qty', 'consumed_qty')def _remaining_func(self):如果 self.consumed_qty 或 self.qty:self.remaining_qty = self.consumed_qty - self.qty

如果我在 bsi.production.order.lines 上添加多个 isbn,它会抛出我:

值错误预期单例:bsi.production.order.lines(10, 11)

有什么想法吗?

编辑

重复是一种不同的情况,实际上我已经改变了我的方法来匹配另一个问题中解释的方法,但没有成功.所以这不是真的,或者至少不是仅 api 的问题.

解决方案

在你的例子中,它在 order_lines 中找到了不止一个记录集,你试图得到 isbn从中产生的价值.

尝试使用以下代码:

@api.multi@api.depends('order_lines', 'order_lines.isbn')def checkit(自我):自我记录:如果 record.order_lines:对于 record.order_lines 中的行:如果 line.isbn:返回行.isbn别的:raise Warning(('输入 至少 1 个 ISBN 以 生产'))

有关这些错误的详细信息.你可以参考我的博客.>

I have this method, which should loop on a One2many object, but the actual loop isn't working, I mean, if I add just one line it works fine, but if I add more than one line, than it throws me the singleton error:

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

These are the two objects on which this method is based upon:

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

If I add more than one isbn on bsi.production.order.lines it throws me:

ValueError

Expected singleton: bsi.production.order.lines(10, 11)

Any ideas?

EDIT

The duplicate is a different situation, and actually I've changed my method to match the one explained in the other question, with no success. So it's not really, or at least not an api-only issue.

解决方案

In your case, it's found more then one record set in order_lines and you tried to get isbn value from it.

Try with following code:

@api.multi
@api.depends('order_lines', 'order_lines.isbn')
def checkit(self):
    for record in self:
        if record.order_lines:
            for line in record.order_lines:
                if line.isbn:  
                    return line.isbn
        else:
            raise Warning(('Enter​ ​at least​ ​1​ ​ISBN to produce'))

For details of these error. You may refer my blog.

这篇关于ValueError:预期的单身人士:-Odoo v8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆