Odoo Help


Why does Odoo 9 return "'module' object has no attribute 'many2one'" only sometimes?

David Todd
on 12/7/15, 10:35 AM 2,534 views

Update: Thanks to Pawan for their answer. I found that I was following examples from the older API and didn't think capitalization mattered on the fields. I'd close this question, but I don't have enough Karma to be able do that. 

I'm attempting to build a module for the company I work for and I keep hitting this roadblock.

A little bit of background is I have a field called m_name that uses a many2one field to get the current username. I uninstall the module from the server and restart the server when I introduce new code to be sure that there isn't any conflicts with existing data. I am developing on a Windows server for eventual deployment to a Debian Linux server.

When the server is restarted and I begin the process for installing the module again, I get a trackback similar to the one below:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 599, in _handle_exception
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 636, in dispatch
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 315, in _call_function
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\service\model.py", line 118, in wrapper
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 308, in checked_call
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 887, in __call__
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\http.py", line 465, in response_wrap
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\web\controllers\main.py", line 975, in call_button
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\web\controllers\main.py", line 963, in _call_kw
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\api.py", line 232, in wrapper
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\base\module\module.py", line 459, in button_immediate_install
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\api.py", line 232, in wrapper
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\base\module\module.py", line 533, in _button_immediate_function
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\registry.py", line 385, in new
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\loading.py", line 337, in load_modules
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\loading.py", line 237, in load_marked_modules
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\loading.py", line 123, in load_module_graph
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\module.py", line 324, in load_openerp_module
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\.\openerp\modules\module.py", line 61, in load_module
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\metrics\__init__.py", line 3, in <module>
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\metrics\models.py", line 5, in <module>
  File "C:\Program Files (x86)\Odoo 9.0-20151125\server\openerp\addons\metrics\models.py", line 13, in metrics
AttributeError: 'module' object has no attribute 'many2one'

When this happened to me before, I found that changing m_name to x_name (to show that this is a custom field in the database structure), worked until I started adding code for search filtering. I have since removed the search filter code and still get this error. Any help would be most appreciated, and I'll post my models.py and views.xml file to help give a better idea what I'm doing below.

# -*- coding: utf-8 -*-

# models.py

from openerp import models, fields, api

class metrics(models.Model):

    _name = 'metrics.metrics'

    _defaults = {

        'x_name': lambda self, cr, uid, ctx=None: uid


    # Main fields

    x_name = fields.many2one('res.users')

    m_value = fields.Integer(string='Total', required=True)

    m_task = fields.Selection([('desktop', 'Desktops'), ('laptop', 'Laptops'), ('network', 'Network Equipment')], string='Task', required=True)

    m_date = fields.Datetime(string='Date')

<!-- views.xml -->

<?xml version="1.0" encoding="utf-8"?>



<!-- explicit list view definition -->

<record id="metrics.list" model="ir.ui.view">

<field name="name">metrics list</field>

<field name="model">metrics.metrics</field>

<field name="arch" type="xml">


<field name="x_name"/>

<field name="m_task"/>

<field name="m_value"/>

<field name="m_date"/>




<!-- actions opening views on models -->

<record id="metrics.ActionAdd" model="ir.actions.act_window">

<field name="name">metrics window</field>

<field name="res_model">metrics.metrics</field>

<field name="view_mode">tree,form</field>


<!-- Top menu item -->

<menuitem id="metrics.menu_root" name="Metrics"/>

<!-- menu categories -->

<menuitem id="metrics.menu_1" name="Metrics Reporting" parent="metrics.menu_root"/>

<!-- actions -->

<menuitem action="metrics.ActionAdd" id="metrics.menu_1_1" name="Add" parent="metrics.menu_1"/>

<menuitem action="metrics.ActionView" id="metrics.menu_1_2" name="View" parent="metrics.menu_1"/>

<menuitem action="metrics.ActionModify" id="metrics.menu_1_3" name="Modify" parent="metrics.menu_1"/>

<menuitem action="metrics.ActionDelete" id="metrics.menu_1_4" name="Delete" parent="metrics.menu_1"/>




Please give Pawan an upvote for his answer. How is anybody supposed to get Karma, if nobody is upvoting proper answers??? :-)

Ermin Trevisan
on 12/9/15, 2:12 AM



| 4 4 6
Hyderabad, India

On 12/8/15, 9:02 AM

Please change the 'many2one' to 'Many2one' with capital M, as in odoo8 api field name have initial 

letters capital


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/7/15, 10:35 AM
Seen: 2534 times
Last updated: 12/9/15, 2:20 AM