Python 模块没有吸引多个ONE-Odoo v9社区

Python 模块没有吸引多个ONE-Odoo v9社区,python,openerp,odoo-9,Python,Openerp,Odoo 9,我将从Odoov9社区版中的自定义模块向模型添加一个字段 像这样: 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 acco

我将从Odoov9社区版中的自定义模块向模型添加一个字段

像这样:

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'
2016-08-30 00:04:41807 12893关键odoov9\uuOpenerp.modules.module:无法加载模块借项\贷项\注释
2016-08-30 00:04:41807 12893关键odoov9_uuOpenerp.modules.module:“module”对象没有属性“manyOne”
2016-08-30 00:04:41808 12893错误odoov9_uOpenerp.modules.registry:无法加载注册表
回溯(最近一次呼叫最后一次):
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/registry.py”,第386行,新格式
加载模块(注册表数据库、强制演示、状态、更新模块)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/load.py”,第334行,加载模块
强制、状态、报告、加载的\u模块、更新\u模块)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/loading.py”,第237行,加载标记的模块
已加载、已处理=加载\u模块\u图形(cr、图形、progressdict、报告=报告、跳过\u模块=加载的\u模块、执行\u检查=执行\u检查)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/load.py”,第123行,加载模块图
加载\u openerp\u模块(package.name)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/module.py”,第324行,加载openerp\u模块
__导入(openerp.addons.+模块名称)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/module.py”,第61行,加载模块
mod=imp.load_模块('openerp.addons.'+模块部分,f,路径,描述)
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit\u credit\u note/\u init\u.py”,第31行,in
导入模型
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit\u credit\u note/models/\u init\u.py”,第1行,在
进口借贷
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit\u credit\u note/models/debit\u credit.py”,第27行
课程退款(型号.型号):
文件“/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit\u credit\u note/models/debit\u credit.py”,第36行,退款
“日记账id”:字段.manyOne('account.journal'、'return journal',help='您可以在此处选择用于将创建的贷记单的日记账。如果您将该字段留空,它将使用与当前发票相同的日记账。'),
AttributeError:“模块”对象没有属性“manyOne”
有人能解释这件事吗


我对此感到非常困惑,以前从未出现过此错误。

如果您是从已定义的模块继承,则不需要定义
\u name
变量,只需定义
\u inherit
变量即可

当您导入新api的
字段时,会出现错误“Module has not attribute manyOne”,但定义它的方式是旧api。如果在新api中编写代码,最大递归错误也应该得到解决

如果您正在为ODOO9编写此模块,那么最好在新的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.')

上面的代码应该可以正常工作

看起来这可能是一个区分大小写的问题:
manyOne
应该将
M
大写。非常感谢您,仍然习惯于v7,lol,但现在我遇到了另一个错误,RuntimeError:调用Python对象时超过了最大递归深度,lol,我想我应该为此打开另一个问题。。。谢谢您定义
\u name
也没有问题。但您的答案是正确的,应该采用新的api样式。