ValueError混合苹果和橘子:my.model()<错 - Odoo v8

时间:2017-08-26 19:49:56

标签: python openerp odoo-8

我有这个向导按钮,它将字段保存为表格中的记录:

@api.multi
def save_data(self, vals):
    vals = {
        self.name : 'name',
        self.date_production : 'date_production',
        self.type_prod : 'type_prod',
        self.product_id : 'product_id',
        self.qty_available : 'qty_available',
        self.print_order2 : 'print_order2',
        self.name_block : 'name_block',
        }
    self.env['bsi.production.order'].create(vals)

这是一个循序渐进的向导,这些是我模型上的原始字段:

class bsi_production_order(models.Model):
_name = 'bsi.production.order'
_inherit = ['mail.thread','text.paper','book.binding', 'book.block','book.edge','book.edition','book.size','cut.off','end.paper','job.rate','paper.master','printing.code', 'mrp.worksheet.contract', 'work.order.isbn.code', 'product.template'] 

@api.model
def create(self, vals):
    if vals.get('name', 'New') == 'New':
        vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.order') or '/'
    return super(bsi_production_order, self).create(vals)

    name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
    date_production = fields.Date(string="Production Date")
    type_prod = fields.Selection([
        ('budgeted','Budgeted'),
        ('nonbudgeted','Non Budgeted'),
        ('direct','Direct Order'),
    ], string='Type of Order', index=True,  
    track_visibility='onchange', copy=False,
    help=" ")
    product_id = fields.Many2one('product.template', string="Product")
    qty_available = fields.Float(string="Qty Available", related="product_id.qty_available")
    production_qty = fields.Float(string="Qty to produce")
    print_order2 = fields.Many2one('bsi.print.order', string="Print Order")
    book_block = fields.Many2one('book.block', )
    name_block = fields.Selection(string="Code", related="book_block.name_block", store=True)

当我尝试从向导中保存记录时,它说:

    ValueError

Mixing apples and oranges: bsi.print.order() < False

有什么想法吗?

修改

这肯定与Many2one和/或One2many字段有关,我还有另一个字段,这是Many2one类型的字段。

还有一些好奇可能与它有关,事实是,当我以传统形式保存bsi.production.order而非向导时,Many2one related字段是显示,但是当我保存新记录时,它们只是以某种方式变空,就像它因某些原因没有保存它们,我已经向它们添加了store=True标志,但仍然是相同的行为。

第二次修改

完整堆栈跟踪:

2017-08-26 22:42:46,786 1688 ERROR bsi_def openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 399, in old_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mrp_worksheet_contract\models\models.py", line 780, in save_data
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mrp_worksheet_contract\models\models.py", line 476, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mrp_worksheet_contract\models\models.py", line 15, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 508, in new_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\product\product.py", line 742, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 372, in old_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mrp_work_order_isbn\models\models.py", line 28, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 508, in new_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mail\mail_thread.py", line 381, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 372, in old_api
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\models.py", line 4101, in create
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\models.py", line 5608, in __lt__
except_orm: ('ValueError', 'Mixing apples and oranges: bsi.print.order() < False')

1 个答案:

答案 0 :(得分:1)

首先定义字典键时首先

             'name' : self. name

并且对于many2one传递id值,因为它是一个对象

             'product_id' : self.product_id.id

希望这可以解决您的问题,因为这是我第一次见到这个错误。

有一件事总是首先检查你的字段,因为如果product_id为空则你有一个错误lkke bool没有属性id