Skip to Content
Menu
This question has been flagged
1 Reply
2869 Views

Hello, I hope you are doing well.


I am using Odoo version 16 enterprise edition. I am attempting to add a phone field to the signup page, making it mandatory. Upon user creation, I want to save the field value in 'contacts'. (res.partner.phone) I have tried extensively to bypass 'do_signup', but to no avail, the phone field always remains empty.


Here is the XML code:










And here is the 'main.py' code that I placed in this path: 'my_custom/controllers/main.py'."



from odoo import http
from odoo.http import request

class AuthSignupExtended(http.Controller):
@http.route('/web/signup', type='http', auth='public', website=True, sitemap=False)
def web_auth_signup(self, *args, **kw):
response = super(AuthSignupExtended, self).web_auth_signup(*args, **kw)

if kw.get('phone'):
# Update the partner's phone field with the provided value
partner_id = response.qcontext.get('partner_id')
if partner_id:
partner = request.env['res.partner'].sudo().browse(partner_id)
partner.write({'phone': kw['phone']})

return response




Avatar
Discard
Author

Hi,

I tried your code, but still phone field is not stored, it's empty.

I have extensively researched before writing down my issue. I've started to suspect that the problem might not be in the code. Could there be another reason preventing data storage?

Best Answer

Hi,

For that set the phone field in the templates like,

<div class="form-group col-12 s_website_form_field s_website_form_required"

data-type="char" data-name="Field">

<div class="row s_col_no_resize s_col_no_bgcolor">

<label class="col-form-label col-sm-auto s_website_form_label"

style="width: 200px"

for="studio1">

<span class="s_website_form_label_content">

Phone

</span>

<span class="s_website_form_mark">

*

</span>

</label>

<div class="col-sm">

<input id="phone" type="text"

class="form-control s_website_form_input"

name="phone" required="1"/>

</div>

</div>

</div>

Then define the controller,

from odoo import http
from odoo.http import request


class WebsiteForm(http.Controller):


@http.route('/submit-customer', type="http", auth="public", website=True)
def submit_customer(self, **post):
request.env['your.model'].sudo().create([
{
'phone': post.get('phone'),
}, ])
return request.render("module_name.template_id")


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 25
1325
3
Nov 24
4889
3
Nov 23
7701
1
Apr 23
2717
0
Jun 15
3156