Module has not attrbiute many2one - Odoo v9 community
<p>I'm adding a field to a model froma custom module in Odoov9 Community edition.</p>

<p>Like this:</p>

<pre><code>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.'),
}
</code></pre>

<p>But when server loads, it throws me this error:</p>

<pre><code>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 &lt;module&gt;
import models
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/models/__init__.py", line 1, in &lt;module&gt;
import debit_credit
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/models/debit_credit.py", line 27, in &lt;module&gt;
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'
</code></pre>

<p>Anybody can shed light on this?</p>

<p>I'm very confused at this, never had this error before.</p>

<p>If you are inheriting from an already defined module, you don't need to define the <code>_name</code> variable, just defining the <code>_inherit</code> variable will work too.</p>

<p>You were getting the error "Module has not attrbiute many2one", as you were importing the <code>fields</code> for the new api but defining it the old api way. The maximum recursion error should also get solved if you write the code in the new api.</p>

<p>If you are writing this module for Odoo 9, it would be a good idea to write it in the new api. Below is your code written with the new api:</p>

<pre><code>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.')
</code></pre>

<p>The above piece of code should work without any problems. </p>

python openerp odoo-9