AttributeError:'bool'对象没有属性'_fields' - Odoo v8

时间:2017-11-04 00:44:41

标签: python openerp odoo-8

我只是在我的模型中添加了一些相关的字段,其他一些字段也可以使用,但对于这个模型,它们不会,这些是我的模型:

class book_block(models.Model):
    _name = 'book.block'

    name = fields.Char(string="Name")
    code = fields.Char(string="Code", size=11)
    size_code = fields.Many2one('bsi.book.block.size', string="Size")
    text_paper = fields.Many2one('text.paper', string="Text Paper")
    n_pages_one_color = fields.Integer(string="N° of pages 1 color")
    adnl_n_pages_one_color = fields.Integer(string="Additional N° of pages one color")

class mrp_worksheet_contract(models.Model):
    _name = 'mrp.worksheet.contract'

    @api.model
    def create(self, vals):
        if vals.get('name', 'New') == 'New':
            vals['name'] = self.env['ir.sequence'].next_by_code('mrp.worksheet.contract') or '/'
        return super(mrp_worksheet_contract, self).create(vals)

    name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
    date = fields.Date(string="Date")
    book_block = fields.Many2one('book.block', string="Book Block")
    n_pages_one_color = fields.Integer(string="N of pages one color", related="book_block.n_pages_one_color")
    adnl_n_pages_one_color = fields.Integer(string="Additional N° of pages one color", related="book_block.adnl_n_pages_one_color")

book_block字段没问题,问题出现在n_pages_one_coloradnl_n_pages_one_color字段中,它引发了我:

Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\base\module\module.py", line 447, in button_immediate_install
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\base\module\module.py", line 495, in _button_immediate_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\modules\registry.py", line 370, in new
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\modules\loading.py", line 355, in load_modules
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\modules\loading.py", line 255, in load_marked_modules
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\modules\loading.py", line 156, in load_module_graph
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\modules\registry.py", line 194, in setup_models
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 372, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 3010, in _setup_fields
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 468, in setup
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 514, in _setup_related
AttributeError: 'bool' object has no attribute '_fields'

我没有得到它,它应该有效,我没有看到任何错误,即使book_block Many2one字段是好的,那么,这是什么交易?

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

可能你需要从openerp导入'_'。就像这样:

from openerp.tools.translate import _

答案 1 :(得分:1)

不引用布尔(非布尔)字段。从<< strong> _setup_related 方法,根据源代码,该方法:设置相关字段的属性。因此,我建议您检查具有相关属性的任何字段。 并检查 book_block 模型中是否存在 adnl_n_pages_one_color 字段。