-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from onesteinbv/16.0-update-website_membership…
…_registration_partner_contact_birthdate Updated website_membership_registration_partner_contact_birthdate module
- Loading branch information
Showing
4 changed files
with
58 additions
and
66 deletions.
There are no files selected for viewing
42 changes: 32 additions & 10 deletions
42
website_membership_registration_partner_contact_birthdate/controllers/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
website_membership_registration_partner_contact_birthdate/controllers/portal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters