2016-08-30 164 views
1

我正在向Odoov9社區版的自定義模塊中的模型添加一個字段。模塊沒有attrbiute many2one - Odoo v9社區

像這樣:

import logging 
from openerp import api, fields, models, _ 
from openerp.exceptions import UserError, ValidationError 
from openerp.tools.safe_eval import safe_eval as eval 

class refund(models.Model): 

"""Inherits account.invoice.refund and adds journal_id field""" 
    _name = "account.invoice.refund" 
    _inherit = "account.invoice.refund" 

    _columns = { 
     'journal_id': fields.many2one('account.journal', 'Refund Journal', help='You can select here the journal to use for the credit note that will be created. If you leave that field empty, it will use the same journal as the current invoice.'), 
} 

但是,當服務器負載,它將引發我這個錯誤:

2016-08-30 00:04:41,807 12893 CRITICAL odoov9_ openerp.modules.module: Couldn't load module debit_credit_note 
2016-08-30 00:04:41,807 12893 CRITICAL odoov9_ openerp.modules.module: 'module' object has no attribute 'many2one' 
2016-08-30 00:04:41,808 12893 ERROR odoov9_ openerp.modules.registry: Failed to load registry 
Traceback (most recent call last): 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/registry.py", line 386, in new 
openerp.modules.load_modules(registry._db, force_demo, status, update_module) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/loading.py", line 334, in load_modules 
force, status, report, loaded_modules, update_module) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/loading.py", line 237, in load_marked_modules 
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/loading.py", line 123, in load_module_graph 
load_openerp_module(package.name) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/module.py", line 324, in load_openerp_module 
__import__('openerp.addons.' + module_name) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/module.py", line 61, in load_module 
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/__init__.py", line 31, in <module> 
import models 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/models/__init__.py", line 1, in <module> 
import debit_credit 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/models/debit_credit.py", line 27, in <module> 
class refund(models.Model): 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/models/debit_credit.py", line 36, in refund 
'journal_id': fields.many2one('account.journal', 'Refund Journal', help='You can select here the journal to use for the credit note that will be created. If you leave that field empty, it will use the same journal as the current invoice.'), 
AttributeError: 'module' object has no attribute 'many2one' 

任何人都可以在此揭示?

我對此很困惑,以前從未有過這個錯誤。

+1

它看起來可能是一個大小寫敏感的問題:https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.fields.Many2one Many2one應該有大寫的M。 – darthbith

+0

非常感謝您,仍然習慣v7,lol,但現在我有另一個錯誤,RuntimeError:調用Python對象時超出最大遞歸深度,哈哈,我猜應該爲此打開另一個問題...謝謝 – NeoVe

回答

2

如果您繼承自已定義的模塊,則無需定義_name變量,只需定義_inherit變量即可。

當您爲新的api導入fields,但將其定義爲舊的api方式時,您收到錯誤「Module has not attrbiute many2one」。如果您在新的API中編寫代碼,最大的遞歸錯誤也應該得到解決。

如果您正在爲Odoo 9編寫此模塊,最好將它寫入新的api中。下面是你的代碼寫入新的API:

import logging 
from openerp import api, fields, models, _ 
from openerp.exceptions import UserError, ValidationError 
from openerp.tools.safe_eval import safe_eval as eval 

class refund(models.Model): 
_inherit = "account.invoice.refund" 

journal_id = fields.Many2one('account.journal', string='Refund Journal', help='You can select here the journal to use for the credit note that will be created. If you leave that field empty, it will use the same journal as the current invoice.') 

上面這段代碼應該沒有任何問題的工作。

+1

有定義'_name'也沒有問題。但你的回答是正確的,它應該以新的API風格來完成。 – CZoellner

相關問題