diff --git a/website_membership_registration_partner_contact_birthdate/controllers/main.py b/website_membership_registration_partner_contact_birthdate/controllers/main.py index 6a77cf6..ab92a50 100644 --- a/website_membership_registration_partner_contact_birthdate/controllers/main.py +++ b/website_membership_registration_partner_contact_birthdate/controllers/main.py @@ -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 diff --git a/website_membership_registration_partner_contact_birthdate/controllers/portal.py b/website_membership_registration_partner_contact_birthdate/controllers/portal.py index 1de9487..208358c 100644 --- a/website_membership_registration_partner_contact_birthdate/controllers/portal.py +++ b/website_membership_registration_partner_contact_birthdate/controllers/portal.py @@ -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 diff --git a/website_membership_registration_partner_contact_birthdate/templates/website.xml b/website_membership_registration_partner_contact_birthdate/templates/website.xml index 55488ed..ed16319 100644 --- a/website_membership_registration_partner_contact_birthdate/templates/website.xml +++ b/website_membership_registration_partner_contact_birthdate/templates/website.xml @@ -3,60 +3,22 @@ - - - - -