Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
2888 Visualizzazioni

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
Abbandona
Autore

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?

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
lug 25
1340
3
nov 24
4892
3
nov 23
7729
1
apr 23
2733
0
giu 15
3162