Skip to content

Commit

Permalink
Merge pull request #70 from onesteinbv/16.0-update-website_membership…
Browse files Browse the repository at this point in the history
…_registration_partner_contact_birthdate

Updated website_membership_registration_partner_contact_birthdate module
  • Loading branch information
ByteMeAsap authored Nov 18, 2024
2 parents 5a48ebb + be141b1 commit 547da7c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import datetime

from odoo import _

from odoo.addons.website_membership_registration.controllers.main import (
MembershipRegistrationController,
)


class MembershipRegistrationControllerGithub(MembershipRegistrationController):
class MembershipRegistrationControllerBirthDate(MembershipRegistrationController):
def _validate_membership_birthdate(self, birthdate):
error_message, birthdate_valid = "", True
if birthdate:
try:
birthdate = datetime.datetime.strptime(birthdate, "%Y-%m-%d")
except ValueError:
birthdate_valid = False
error_message = _("Birth Date is invalid.")
return birthdate, birthdate_valid, error_message

def _get_error_message_list(self, validation_data, error_data):
error_list = super(
MembershipRegistrationControllerBirthDate, self
)._get_error_message_list(validation_data, error_data)
if not validation_data["member_birthdate_date"]:
error_list.append(error_data["member_birthdate_date"])
return error_list

def _get_partner_and_validation_data(self, post):
partner_data, validation_data, error_data = super(
MembershipRegistrationControllerGithub, self
MembershipRegistrationControllerBirthDate, self
)._get_partner_and_validation_data(post)
partner_data["member_birthdate_date"] = post.get("member_birthdate_date", "")
(
partner_data["member_birthdate_date"],
validation_data["member_birthdate_date"],
error_data["member_birthdate_date"],
) = self._validate_membership_birthdate(post["member_birthdate_date"])
return partner_data, validation_data, error_data

def _get_new_member_vals_dict(self, partner_data):
vals = super(
MembershipRegistrationControllerGithub, self
MembershipRegistrationControllerBirthDate, self
)._get_new_member_vals_dict(partner_data)
if partner_data.get("member_github_login"):
vals["github_login"] = partner_data["member_github_login"]
if partner_data.get("member_gitlab_username"):
vals["gitlab_username"] = partner_data["member_gitlab_username"]
if partner_data.get("member_gitlab_email"):
vals["gitlab_email"] = partner_data["member_gitlab_email"]
if partner_data.get("member_birthdate_date"):
vals["birthdate_date"] = partner_data["member_birthdate_date"]
return vals
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import datetime

from odoo import _

from odoo.addons.portal.controllers.portal import CustomerPortal


class CustomerPortalMembership(CustomerPortal):
CustomerPortal.OPTIONAL_BILLING_FIELDS += ["birthdate_date"]

def details_form_validate(self, data, partner_creation=False):
error, error_message = super(
CustomerPortalMembership, self
).details_form_validate(data, partner_creation=partner_creation)
if data.get("birthdate_date"):
try:
datetime.datetime.strptime(data.get("birthdate_date"), "%Y-%m-%d")
except ValueError:
error["birthdate_date"] = "error"
error_message.append(_("Birth Date is invalid."))
return error, error_message
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,22 @@
<!-- Template of page my/account -->
<template id="portal_my_details_fields" inherit_id="portal.portal_my_details_fields">
<xpath expr="//input[@name='name']/.." position="after">
<div t-attf-class="mb-3 #{error.get('github_login') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="name">Github Login</label>
<input type="text" name="github_login" t-attf-class="form-control #{error.get('github_login') and 'is-invalid' or ''}" t-att-value="partner.github_login" />
</div>
<div t-attf-class="mb-3 #{error.get('gitlab_username') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="name">Gitlab Username</label>
<input type="text" name="gitlab_username" t-attf-class="form-control #{error.get('gitlab_username') and 'is-invalid' or ''}" t-att-value="partner.gitlab_username" />
</div>
<div t-attf-class="mb-3 #{error.get('gitlab_email') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="name">Gitlab Email</label>
<input type="text" name="gitlab_email" t-attf-class="form-control #{error.get('gitlab_email') and 'is-invalid' or ''}" t-att-value="partner.gitlab_email" />
</div>
</xpath>
</template>

<template id="github_login" inherit_id="website_membership_registration.membership_registration_form" name="Github Login on membership registration" priority="40">
<xpath expr="//div[@id='personal_data']" position="inside">
<div class="mb-3 col-12" data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor" id="div_github_login">
<label class="col-form-label col-sm-auto" style="width: 200px" for="member_github_login">
<span>Github Login</span>
</label>
<div class="col-sm">
<input class="form-control" type="text" name="member_github_login" t-att-value="member_github_login"/>
</div>
</div>
</div>
</xpath>
</template>

<template id="gitlab_username" inherit_id="website_membership_registration.membership_registration_form" name="Gitlab username on membership registration" priority="41">
<xpath expr="//div[@id='personal_data']" position="inside">
<div class="mb-3 col-12" data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor" id="div_gitlab_username">
<label class="col-form-label col-sm-auto" style="width: 200px" for="member_gitlab_username">
<span>Gitlab Username</span>
</label>
<div class="col-sm">
<input class="form-control" type="text" name="member_gitlab_username" t-att-value="member_gitlab_username"/>
</div>
</div>
<div t-attf-class="mb-3 #{error.get('birthdate_date') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="name">Birth Date</label>
<input type="date" name="birthdate_date" t-attf-class="form-control #{error.get('birthdate_date') and 'is-invalid' or ''}" t-att-value="partner.birthdate_date" />
</div>
</xpath>
</template>

<template id="gitlab_email" inherit_id="website_membership_registration.membership_registration_form" name="Gitlab Email on membership registration" priority="42">
<template id="birthdate_date" inherit_id="website_membership_registration.membership_registration_form" name="Birth Date on membership registration" priority="40">
<xpath expr="//div[@id='personal_data']" position="inside">
<div class="mb-3 col-12" data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor" id="div_gitlab_email">
<label class="col-form-label col-sm-auto" style="width: 200px" for="member_gitlab_email">
<span>Gitlab Email</span>
<div class="row s_col_no_resize s_col_no_bgcolor" id="div_member_birthdate_date">
<label class="col-form-label col-sm-auto" style="width: 200px" for="member_birthdate_date">
<span>Birth Date</span>
</label>
<div class="col-sm">
<input class="form-control" type="text" name="member_gitlab_email" t-att-value="member_gitlab_email"/>
<input class="form-control" type="date" name="member_birthdate_date" t-att-value="member_birthdate_date"/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
<odoo>
<template id="snippet_options" inherit_id="website_membership_registration.snippet_options" name="membership registration snippet options">
<xpath expr="//div[@data-js='WebsiteMembershipRegistrationPage']" position="inside">
<we-checkbox string="Github Login"
data-customize-website-views="website_membership_registration_partner_cde.github_login"
data-no-preview="true"
data-reload="/"/>
<we-checkbox string="Gitlab Username"
data-customize-website-views="website_membership_registration_partner_cde.gitlab_username"
data-no-preview="true"
data-reload="/"/>
<we-checkbox string="Gitlab Email"
data-customize-website-views="website_membership_registration_partner_cde.gitlab_email"
<we-checkbox string="Birth Date"
data-customize-website-views="website_membership_registration_partner_contact_birthdate.birthdate_date"
data-no-preview="true"
data-reload="/"/>
</xpath>
Expand Down

0 comments on commit 547da7c

Please sign in to comment.