Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2878 Lượt xem

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




Ảnh đại diện
Huỷ bỏ
Tác giả

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?

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
1339
3
thg 11 24
4892
3
thg 11 23
7724
1
thg 4 23
2728
0
thg 6 15
3160