I am working on a customize module in odoo 18, where admin can add or upload cnp number(identification number) , new user will come and put their cnp number if it is valid they will redirect to registration page and use built in registration flow, here is my user_cnp module with respective code,
user_cnp/controllers/main.py,
from odoo import http
from odoo.http import request
class UserCnpController(http.Controller):
@http.route('/register', type='http', auth='public', website=True)
def register_page(self, **kw):
if request.httprequest.method == 'POST':
cnp = kw.get('cnp')
if cnp and len(cnp) == 6:
# Check if the CNP exists in the database
cnp_record = request.env['cnp.validation'].sudo().search([('cnp_number', '=', cnp)], limit=1)
if cnp_record:
# Redirect to the built-in signup page with the CNP pre-filled
return request.redirect(f"/web/signup?cnp={cnp}")
else:
# Render the same page with an error message
return request.render('user_cnp.register_page', {'error': 'CNP not found'})
return request.render('user_cnp.register_page', {})
user_cnp/signup.py
from odoo.addons.auth_signup.controllers.main import AuthSignupHome
from odoo.http import request
class AuthSignupHomeInherit(AuthSignupHome):
def do_signup(self, qcontext):
cnp = qcontext.get('cnp')
if cnp:
# Validate the CNP
cnp_record = request.env['cnp.validation'].sudo().search([('cnp_number', '=', cnp)], limit=1)
if not cnp_record:
qcontext['error'] = "Invalid CNP Number"
return request.render('auth_signup.signup', qcontext)
# Call the original signup method
super(AuthSignupHomeInherit, self).do_signup(qcontext)
user_cnp/models/cnp_validation.py
from odoo import models, fields
class CnpValidation(models.Model):
_name = 'cnp.validation'
_description = 'CNP Validation'
cnp_number = fields.Char(string='CNP Number', required=True)
description = fields.Text(string='Description')
user_cnp/security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_cnp_validation_user,access_cnp_validation_user,model_cnp_validation,base.group_user,1,0,0,0
access_cnp_validation_admin,access_cnp_validation_admin,model_cnp_validation,base.group_system,1,1,1,1
user_cnp/views/cnp_views.xml,
<odoo>
<template id="register_page" name="Registration Page">
<h2>Register Your Account</h2>
<form action="/register" method="POST">
<label for="cnp">Enter Your CNP Number (6 digits):</label>
<input type="text" id="cnp" name="cnp" required="True"/>
<button type="submit">Submit</button>
</form>
</template>
<template id="registration_form" name="Registration Form">
<h2>Complete Your Registration</h2>
<!-- registration fields -->
</template>
<!-- Backend Menu Items and Actions for CNP Management -->
<menuitem id="menu_user_cnp" name="CNP Validation" parent="base.menu_administration" />
<!-- Action to open the CNP List in the backend -->
<record id="action_cnp_list" model="ir.actions.act_window">
<field name="name">CNP List</field>
<field name="res_model">cnp.validation</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_cnp_tree"/>
</record>
<!-- Submenu for the CNP List -->
<menuitem id="menu_user_cnp_list" name="CNP List" parent="menu_user_cnp" action="action_cnp_list"/>
<!-- The Tree View for CNP numbers -->
<record id="view_cnp_tree" model="ir.ui.view">
<field name="name">cnp.validation.tree</field>
<field name="model">cnp.validation</field>
<field name="arch" type="xml">
<tree>
<field name="cnp_number"/>
</tree>
</field>
</record>
<!-- The Form View for a single CNP entry -->
<record id="view_cnp_form" model="ir.ui.view">
<field name="name">cnp.validation.form</field>
<field name="model">cnp.validation</field>
<field name="arch" type="xml">
<form string="CNP Validation">
<sheet>
<group>
<field name="cnp_number"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
user_cnp/views/signup_inherit.py,
<odoo>
<template id="signup_form_inherit" inherit_id="auth_signup.signup">
<xpath expr="//div[@id='signup_form']" position="inside">
<div class="form-group">
<label for="cnp">CNP Number</label>
<input type="text" name="cnp" id="cnp" class="form-control" value=""/>
</div>
</xpath>
</template>
</odoo>
user_cnp/manifest.py,
{
'name': 'User CNP Validation',
'version': '1.0',
'category': 'Custom',
'author': 'Muntasir Mamun',
'depends': ['base', 'website'],
'data': [
'views/cnp_views.xml',
'views/signup_inherit.xml',
'security/ir.model.access.csv',
],
'application': True,
}
Error while activating the app,
RPC_ERROR
Odoo Server Error
Occured on localhost:8069 on model ir.module.module and id 14 on 2025-01-27 10:45:39 GMT
Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/tools/cache.py", line 103, in lookup r = d[key] ~^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/func.py", line 97, in locked return func(inst, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/lru.py", line 33, in getitem a = self.d[obj] ~~~~~~^^^^^ KeyError: ('ir.model.data', <function IrModelData._xmlid_lookup at 0x10501f240>, 'user_cnp.view_cnp_tree')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 537, in _tag_root f(rec) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 400, in _tag_record f_val = self.id_get(f_ref, raise_if_not_found=nodeattr2bool(rec, 'forcecreate', True)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 519, in id_get res = self.model_id_get(id_str, raise_if_not_found) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 525, in model_id_get return self.env['ir.model.data']._xmlid_to_res_model_res_id(id_str, raise_if_not_found=raise_if_not_found) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_model.py", line 2245, in _xmlid_to_res_model_res_id return self._xmlid_lookup(xmlid) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/cache.py", line 110, in lookup value = d[key] = self.method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_model.py", line 2238, in _xmlid_lookup raise ValueError('External ID not found in the system: %s' % xmlid) ValueError: External ID not found in the system: user_cnp.view_cnp_tree
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/http.py", line 1957, in _transactioning return service_model.retrying(func, env=self.env) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/service/model.py", line 137, in retrying result = func() ^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 1924, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 2171, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_http.py", line 329, in _dispatch result = endpoint(**request.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 727, in route_wrapper result = endpoint(self, *args, **params_ok) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/addons/web/controllers/dataset.py", line 40, in call_button action = call_kw(request.env[model], method, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/api.py", line 517, in call_kw result = getattr(recs, name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 75, in check_and_log return method(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 480, in button_immediate_install return self._button_immediate_function(self.env.registry[self._name].button_install) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 604, in _button_immediate_function registry = modules.registry.Registry.new(self._cr.dbname, update_module=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/func.py", line 97, in locked return func(inst, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/registry.py", line 127, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 480, in load_modules processed_modules += load_marked_modules(env, graph, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 364, in load_marked_modules loaded, processed = load_module_graph( ^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 227, in load_module_graph load_data(env, idref, mode, kind='data', package=package) File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 71, in load_data tools.convert_file(env, package.name, filename, idref, mode, noupdate, kind) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 608, in convert_file convert_xml_import(env, module, fp, idref, mode, noupdate) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 679, in convert_xml_import obj.parse(doc.getroot()) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 594, in parse self._tag_root(de) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 550, in _tag_root raise ParseError('while parsing %s:%s, somewhere inside\n%s' % ( odoo.tools.convert.ParseError: while parsing /Users/muntasirmamun/ajvps/addons/user_cnp/views/cnp_views.xml:20, somewhere inside CNP List cnp.validation tree,form
The above server error caused the following client error: RPC_ERROR: Odoo Server Error RPC_ERROR at makeErrorFromResponse (http://localhost:8069/web/assets/debug/web.assets_web.js:29607:19) at XMLHttpRequest. (http://localhost:8069/web/assets/debug/web.assets_web.js:29661:27)
Error in the terminal,
2025-01-27 10:45:39,682 65549 ERROR odoo_reea_test_now odoo.http: Exception during request handling. Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/tools/cache.py", line 103, in lookup r = d[key] ~^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/func.py", line 97, in locked return func(inst, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/lru.py", line 33, in getitem a = self.d[obj] ~~~~~~^^^^^ KeyError: ('ir.model.data', <function IrModelData._xmlid_lookup at 0x10501f240>, 'user_cnp.view_cnp_tree')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 537, in _tag_root f(rec) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 400, in _tag_record f_val = self.id_get(f_ref, raise_if_not_found=nodeattr2bool(rec, 'forcecreate', True)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 519, in id_get res = self.model_id_get(id_str, raise_if_not_found) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 525, in model_id_get return self.env['ir.model.data']._xmlid_to_res_model_res_id(id_str, raise_if_not_found=raise_if_not_found) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_model.py", line 2245, in _xmlid_to_res_model_res_id return self._xmlid_lookup(xmlid) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/cache.py", line 110, in lookup value = d[key] = self.method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_model.py", line 2238, in _xmlid_lookup raise ValueError('External ID not found in the system: %s' % xmlid) ValueError: External ID not found in the system: user_cnp.view_cnp_tree
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/Users/muntasirmamun/ajvps/odoo/http.py", line 2366, in call response = request._serve_db() ^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 1894, in _serve_db return self._transactioning( ^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 1957, in _transactioning return service_model.retrying(func, env=self.env) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/service/model.py", line 137, in retrying result = func() ^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 1924, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 2171, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_http.py", line 329, in _dispatch result = endpoint(**request.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/http.py", line 727, in route_wrapper result = endpoint(self, *args, **params_ok) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/addons/web/controllers/dataset.py", line 40, in call_button action = call_kw(request.env[model], method, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/api.py", line 517, in call_kw result = getattr(recs, name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 75, in check_and_log return method(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 480, in button_immediate_install return self._button_immediate_function(self.env.registry[self._name].button_install) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/addons/base/models/ir_module.py", line 604, in _button_immediate_function registry = modules.registry.Registry.new(self._cr.dbname, update_module=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/.pyenv/versions/3.12.2/lib/python3.12/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/tools/func.py", line 97, in locked return func(inst, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/registry.py", line 127, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 480, in load_modules processed_modules += load_marked_modules(env, graph, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 364, in load_marked_modules loaded, processed = load_module_graph( ^^^^^^^^^^^^^^^^^^ File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 227, in load_module_graph load_data(env, idref, mode, kind='data', package=package) File "/Users/muntasirmamun/ajvps/odoo/modules/loading.py", line 71, in load_data tools.convert_file(env, package.name, filename, idref, mode, noupdate, kind) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 608, in convert_file convert_xml_import(env, module, fp, idref, mode, noupdate) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 679, in convert_xml_import obj.parse(doc.getroot()) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 594, in parse self._tag_root(de) File "/Users/muntasirmamun/ajvps/odoo/tools/convert.py", line 550, in _tag_root raise ParseError('while parsing %s:%s, somewhere inside\n%s' % ( odoo.tools.convert.ParseError: while parsing /Users/muntasirmamun/ajvps/addons/user_cnp/views/cnp_views.xml:20, somewhere inside CNP List cnp.validation tree,form
I tried rerun and also updated app list but still facing the same issue