0

Here is my code for custom module where im inheriting the 'res.users' and adding a custom field to existing formview

from odoo import models, fields, api



class CustomUser(models.Model):
    _inherit = 'res.users'

    # Add your custom fields here
    custom_field = fields.Char(string="Custom Field")

and here is my xml file where i have inherited the form view and by using xpath i have added the custom field

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Define a new view for your custom model -->
    <record id="view_custom_user_form" model="ir.ui.view">
        <field name="name">custom.user.form</field>
        <field name="model">res.users</field>
        <field name="inherit_id" ref="base.view_users_form"/>
        <field name="arch" type="xml">
            
            <xpath expr="//field[@name='login']" position="after">
                <field name="custom_field"/>
            </xpath>
        </field>
    </record>

but this throw error that error is res.users.custom field does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 970, in __get__
    value = env.cache.get(record, self)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 793, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'res.users(1,).partner_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_cron.py", line 238, in _process_jobs
    registry[cls._name]._process_job(job_cr, job, lock_cr)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_cron.py", line 139, in _process_job
    now = fields.Datetime.context_timestamp(cron, datetime.now())
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1883, in context_timestamp
    tz_name = record._context.get('tz') or record.env.user.tz
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1019, in __get__
    self.compute_value(recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1175, in compute_value
    records._compute_field_value(self)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4059, in _compute_field_value
    field.compute(self)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 541, in _compute_related
    values = [first(value[name]) for value in values]
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 541, in <listcomp>
    values = [first(value[name]) for value in values]
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 5662, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 2483, in __get__
    return super().__get__(records, owner)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 996, in __get__
    recs._fetch_field(self)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3065, in _fetch_field
    self._read(fnames)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/res_users.py", line 447, in _read
    super(Users, self)._read(fields)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3132, in _read
    cr.execute(query_str, params + [sub_ids])
  File "<decorator-gen-3>", line 2, in execute
  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 101, in check
    return f(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 298, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: column res_users.custom_field does not exist
LINE 1: ...share", "res_users"."company_id" as "company_id", "res_users...
                                                             ^


2023-08-24 10:26:12,644 32 INFO ? odoo.http: HTTP Configuring static files
2023-08-24 10:26:17,673 32 INFO devawais odoo.modules.loading: loading 1 modules...
2023-08-24 10:26:17,700 32 INFO devawais odoo.modules.loading: 1 modules loaded in 0.03s, 0 queries (+0 extra)
2023-08-24 10:26:17,727 32 WARNING devawais odoo.modules.graph: module customize_knk: not installable, skipped
2023-08-24 10:26:17,740 32 INFO devawais odoo.modules.loading: loading 84 modules...
2023-08-24 10:26:17,968 32 WARNING devawais py.warnings: /usr/lib/python3/dist-packages/jinja2/sandbox.py:82: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableSet, MutableMapping, MutableSequence

2023-08-24 10:26:18,536 32 INFO devawais odoo.modules.loading: 84 modules loaded in 0.80s, 0 queries (+0 extra)
2023-08-24 10:26:18,537 32 ERROR devawais odoo.modules.loading: Some modules are not loaded, some dependencies or manifest may be missing: ['customize_knk']
2023-08-24 10:26:19,163 32 INFO devawais odoo.modules.loading: Modules loaded.
2023-08-24 10:26:19,171 32 INFO devawais odoo.addons.base.models.ir_http: Generating routing map for key None
2023-08-24 10:26:19,258 32 ERROR devawais odoo.sql_db: bad query: SELECT "res_users"."id" as "id", "res_users"."partner_id" as "partner_id", "res_users"."login" as "login", "res_users"."signature" as "signature", "res_users"."active" as "active", "res_users"."action_id" as "action_id", "res_users"."share" as "share", "res_users"."company_id" as "company_id", "res_users"."custom_field" as "custom_field", "res_users"."notification_type" as "notification_type", "res_users"."odoobot_state" as "odoobot_state", "res_users"."odoobot_failed" as "odoobot_failed", "res_users"."sale_team_id" as "sale_team_id", "res_users"."helpdesk_target_closed" as "helpdesk_target_closed", "res_users"."helpdesk_target_rating" as "helpdesk_target_rating", "res_users"."helpdesk_target_success" as "helpdesk_target_success", "res_users"."create_uid" as "create_uid", "res_users"."create_date" as "create_date", "res_users"."write_uid" as "write_uid", "res_users"."write_date" as "write_date" FROM "res_users" WHERE "res_users".id IN (2)
ERROR: column res_users.custom_field does not exist
LINE 1: ...share", "res_users"."company_id" as "company_id", "res_users...
                                                             ^

2023-08-24 10:26:19,262 32 INFO devawais werkzeug: 206.84.148.50 - - [24/Aug/2023 10:26:19] "GET /web HTTP/1.0" 500 - 34 0.041 6.572
2023-08-24 10:26:19,271 32 ERROR devawais werkzeug: Error on request:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 270, in run_wsgi
    execute(self.server.app)
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 258, in execute
    application_iter = app(environ, start_response)
  File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 122, in application
    return ProxyFix(application_unproxied)(environ, start_response)
  File "/usr/lib/python3/dist-packages/werkzeug/contrib/fixers.py", line 152, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 99, in application_unproxied
    result = odoo.http.root(environ, start_response)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1306, in __call__
    return self.dispatch(environ, start_response)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1272, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 766, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1479, in dispatch
    result = ir_http._dispatch()
  File "/usr/lib/python3/dist-packages/odoo/addons/auth_signup/models/ir_http.py", line 19, in _dispatch
    return super(Http, cls)._dispatch()
  File "/usr/lib/python3/dist-packages/odoo/addons/web_editor/models/ir_http.py", line 21, in _dispatch
    return super(IrHttp, cls)._dispatch()
  File "/usr/lib/python3/dist-packages/odoo/addons/utm/models/ir_http.py", line 29, in _dispatch
    response = super(IrHttp, cls)._dispatch()
  File "/usr/lib/python3/dist-packages/odoo/addons/http_routing/models/ir_http.py", line 508, in _dispatch
    result = super(IrHttp, cls)._dispatch()
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 241, in _dispatch
    return cls._handle_exception(e)
  File "/usr/lib/python3/dist-packages/odoo/addons/utm/models/ir_http.py", line 34, in _handle_exception
    response = super(IrHttp, cls)._handle_exception(exc)
  File "/usr/lib/python3/dist-packages/odoo/addons/http_routing/models/ir_http.py", line 598, in _handle_exception
    return super(IrHttp, cls)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 209, in _handle_exception
    return request._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 745, in _handle_exception
    return super(HttpRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 316, in _handle_exception
    raise exception.with_traceback(None) from new_cause
psycopg2.ProgrammingError: column res_users.custom_field does not exist
LINE 1: ...share", "res_users"."company_id" as "company_id", "res_users...

i am using docker container for odoo v14 enterprise i have run the docker commands to update the module and database but both of method does'nt work if any one help me to debug this would be appreciable being part of stack community thanks

1 Answers1

0

Make sure the folder structure is like this:

custom_modules\
custom_modules/models\
custom_modules/models/__init__.py\
custom_modules/models/res_users.py\
custom_modules/views\
custom_modules/views/res_users_views.xml\
custom_modules/__init__.py\
custom_modules/__manifest__.py

Inside custom_modules/__init__.py you import models

from . import models

Inside custom_modules/models/__init__.py you import res_users

from . import res_users

Inside custom_modules/__manifest__.py you add views to data

{
...
 'data': ['views/res_users.xml']
...
}

and if you make changes to python code (refactor methods) -> restart the server and if you make changes to xml code, and new fields -> upgrade the module