Skip to content

Instantly share code, notes, and snippets.

@3mrdev
Last active October 1, 2023 08:05
Show Gist options
  • Save 3mrdev/080600b782c26458ec508bbe39cd5bf2 to your computer and use it in GitHub Desktop.
Save 3mrdev/080600b782c26458ec508bbe39cd5bf2 to your computer and use it in GitHub Desktop.
How to add more fields to the sign up page in Odoo?
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Inherit Form View to Modify it -->
<record id="kod_res_partner_inherit" model="ir.ui.view">
<field name="name">kod.res.partner.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Signup Information" autofocus="autofocus">
<group>
<field name="last_name"/>
</group>
</page>
</xpath>
</field>
</record>
<template id="add_fields_to_ecommerce_address" inherit_id="website_sale.address" priority="-1">
<xpath expr="//form/div[1]" position="replace">
<div class="form-row">
<div t-attf-class="form-group #{error.get('name') and 'o_has_error' or ''} col-lg-12 div_name">
<label class="col-form-label" for="name">Name</label>
<input type="text" name="name" t-attf-class="form-control #{error.get('name') and 'is-invalid' or ''}" t-att-value="'name' in checkout and checkout['name']"/>
</div>
</div>
</xpath>
</template>
<template id="add_fields_to_signup" inherit_id="auth_signup.fields">
<xpath expr="//div[2]" position="replace">
<div class="form-group field-name">
<label for="name">First Name</label>
<input type="text" name="name" t-att-value="name" id="name" class="form-control form-control-sm" placeholder="e.g. Omer"
required="required" t-att-readonly="'readonly' if only_passwords else None"
t-att-autofocus="'autofocus' if login and not only_passwords else None" />
</div>
<div class="form-group field-last_name">
<label for="name">Last Name</label>
<input type="text" name="last_name" t-att-value="last_name" id="last_name" class="form-control form-control-sm" placeholder="e.g. Mohammed Ali"
required="required" t-att-readonly="'readonly' if only_passwords else None"
t-att-autofocus="'autofocus' if login and not only_passwords else None" />
</div>
</xpath>
</template>
</data>
</odoo>
import json
from odoo import http
from odoo.exceptions import UserError
from odoo.http import request
from odoo.addons.auth_signup.controllers.main import AuthSignupHome
from odoo.addons.website_sale.controllers.main import WebsiteSale
class AuthSignupHome(AuthSignupHome):
def do_signup(self, qcontext):
# add more fileds to the list after the phone
values = {key: qcontext.get(key) for key in ('login',
'name', 'password', 'phone','your_field_goes_here')}
if not values:
raise UserError(_("The form was not properly filled in."))
if values.get('password') != qcontext.get('confirm_password'):
raise UserError(_("Passwords do not match; please retype them."))
supported_lang_codes = [code for code, _ in request.env['res.lang'].get_installed()]
lang = request.context.get('lang', '').split('_')[0]
if lang in supported_lang_codes:
values['lang'] = lang
self._signup_with_values(qcontext.get('token'), values)
request.env.cr.commit()
class WebsiteSale(WebsiteSale):
# add more fileds to the list if you want them to be mandetory
def _get_mandatory_shipping_fields(self):
return ["name"]
def _get_mandatory_billing_fields(self):
return ["name", "email"]
from odoo import fields,models,api
from odoo.exceptions import UserError
class RegisterMoreFields(models.Model):
_inherit = "res.partner"
# add the fileds that you want to the res.partner model ex. last name
last_name = fields.Char()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment