跳至內容
選單
此問題已被標幟
1 回覆
2881 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
7月 25
1339
3
11月 24
4892
3
11月 23
7727
1
4月 23
2731
0
6月 15
3162