gpt4 book ai didi

python - 模块没有属性 Many2one - Odoo v9 社区

转载 作者:行者123 更新时间:2023-12-01 03:43:59 27 4
gpt4 key购买 nike

我正在从 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'

有人可以解释一下吗?

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

最佳答案

如果您从已定义的模块继承,则无需定义 _name 变量,只需定义 _inherit 变量即可。

您收到错误“模块没有 attrbiute Many2one”,因为您正在导入新 api 的字段,但以旧 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.')

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

关于python - 模块没有属性 Many2one - Odoo v9 社区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39217019/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com