Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2880 Представления

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




Аватар
Отменить
Автор

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?

Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июл. 25
1339
3
нояб. 24
4892
3
нояб. 23
7727
1
апр. 23
2731
0
июн. 15
3162