Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
10151 มุมมอง

The default signup form has fields for Email, Name, Password, and Confirm Password.  I want to add the phone number.

I created a custom module and was able to override the HTML form to add the phone input tag.  

But the only way I could get it to save to the DB was to manually change  addons/auth_signup/controller/main.py

    def do_signup(self, qcontext):

        """ Shared helper that creates a res.partner out of a token """

        values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password'))

        assert any([k for k in values.values()]), "The form was not properly filled in."

        assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them."

        self._signup_with_values(qcontext.get('token'), values)

The line causing the issue is values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password')).  If I edit this line and add 'phone' after 'password' it works as expected.

My question is how can I make this change in a custom module instead of hard-coding the change in this file?

 

อวตาร
ละทิ้ง

@Gary,

You definitely can and should make these changes in a custom module as opposed to editing core modules/files.

Could you post the files you have edited on a github gist or repo so that I can take a look?

From what I understand you simply want to add a phone number field to the signup process that will save to the customer's related partner profile after they signup, is that correct?

ผู้เขียน

Luke, thanks for the comment. I was able to get the phone number to save by overriding the method in my custom module as shown below.

ผู้เขียน คำตอบที่ดีที่สุด

I found the documentation here https://www.odoo.com/documentation/8.0/reference/http.html#controllers which explained how to extend a controller.  I overrode this method and was able to get the phone number to save to the DB on signup.

# override do_signup method to allow referred_by_id to be set from sign-up form
class AuthSignupHome(AuthSignupHome):
    def do_signup(self, qcontext):
        """ Shared helper that creates a res.partner out of a token """
        values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password', 'phone'))
        assert any([k for k in values.values()]), "The form was not properly filled in."
        assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them."
        self._signup_with_values(qcontext.get('token'), values)
        request.cr.commit()

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
add fields to signup page แก้ไขแล้ว
2
เม.ย. 25
3247
Write function not working แก้ไขแล้ว
2
พ.ค. 15
7439
0
มี.ค. 15
4532
2
ธ.ค. 23
44197
1
พ.ย. 17
5609