2016-08-30 9 views
1

Odoov9 Community Editionのカスタムモジュールからモデルにフィールドを追加しています。このようモジュールが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に慣れてくれてありがとう、笑、RuntimeError:Pythonオブジェクトを呼び出すときに最大再帰深度を超過しました.Lol、別の質問を開くべきだと思います...ありがとうございました – NeoVe

答えて

2

すでに定義されているモジュールから継承している場合、変数を定義する必要はありません。_inherit変数を定義するだけでも機能します。

新しいAPIのfieldsをインポートしていたのに、古いAPIの方法を定義していたので、「モジュールはたくさんの変更がありません」というエラーが発生しました。新しい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

関連する問題