From a70dbfd6c640a27c46bb1cbf57a9967b694bccf6 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Tue, 11 Aug 2020 15:49:27 +0200 Subject: [PATCH 1/4] Replaces the address field by 2 fields, "street_name" and "house_number", in the "become a cooperator" web page. These 2 new fields really only exist in this web page: Upon submission of the form, the address field is computed and stored in the database, while the "street_name" and "house_number" fields are discarded. --- easy_my_coop/models/coop.py | 5 +- easy_my_coop_website/controllers/main.py | 27 +++++++- .../views/subscription_template.xml | 64 ++++++++++++++----- 3 files changed, 76 insertions(+), 20 deletions(-) diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index 45ad68c..5f4cbbf 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -11,12 +11,14 @@ from addons.base_iban.models.res_partner_bank import validate_iban from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError +# This structure is only used in easy_my_coop_webstite's controller _REQUIRED = [ "email", "firstname", "lastname", "birthdate", - "address", + "street_name", + "house_number", "share_product_id", "ordered_parts", "zip_code", @@ -37,6 +39,7 @@ class SubscriptionRequest(models.Model): _name = "subscription.request" _description = "Subscription Request" + # This function is only used in easy_my_coop_webstite's controller def get_required_field(self): required_fields = _REQUIRED company = self.env["res.company"]._company_default_get() diff --git a/easy_my_coop_website/controllers/main.py b/easy_my_coop_website/controllers/main.py index 20e07c4..960c010 100644 --- a/easy_my_coop_website/controllers/main.py +++ b/easy_my_coop_website/controllers/main.py @@ -7,7 +7,17 @@ from odoo.http import request from odoo.tools.translate import _ # Only use for behavior, don't stock it -_TECHNICAL = ["view_from", "view_callback"] +_TECHNICAL = [ + "view_from", + "view_callback" +] + +# transient fields used to compute the address field +_EXTRA_FIELDS = [ + "street_name", + "house_number" +] + # Allow in description _BLACKLIST = [ "id", @@ -27,7 +37,8 @@ _COOP_FORM_FIELD = [ "birthdate", "iban", "share_product_id", - "address", + "street_name", + "house_number", "city", "zip_code", "country_id", @@ -50,7 +61,8 @@ _COMPANY_FORM_FIELD = [ "birthdate", "iban", "share_product_id", - "address", + "street_name", + "house_number", "city", "zip_code", "country_id", @@ -407,6 +419,11 @@ class WebsiteSubscription(http.Controller): and field_name not in _BLACKLIST ): values[field_name] = field_value + elif ( + field_name in _EXTRA_FIELDS + and field_name not in _BLACKLIST + ): + values[field_name] = field_value # allow to add some free fields or blacklisted field like ID elif field_name not in _TECHNICAL: post_description.append( @@ -450,6 +467,10 @@ class WebsiteSubscription(http.Controller): values["share_product_id"] = self.get_selected_share(kwargs).id + values["address"] = kwargs.get("street_name") + ", " + kwargs.get("house_number") + del values["street_name"] + del values["house_number"] + if is_company: if kwargs.get("company_register_number", is_company): values["company_register_number"] = re.sub( diff --git a/easy_my_coop_website/views/subscription_template.xml b/easy_my_coop_website/views/subscription_template.xml index f12f8b6..8a89a4a 100644 --- a/easy_my_coop_website/views/subscription_template.xml +++ b/easy_my_coop_website/views/subscription_template.xml @@ -256,18 +256,34 @@ style="margin-left:25%;margin-top:35px;width:59%"> -
+
- + + + + + + +
+ + + +
@@ -650,13 +666,29 @@ for="address">Address
- + + + + + + +
+ + + +
From b096c76d90e55c2c4122ec550faefa7dc4dc3aab Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Mon, 26 Oct 2020 16:15:22 +0100 Subject: [PATCH 2/4] In the become a (company) cooperator forms, remembers confirmation email when there's no problem with it. Signed-off-by: Cyrille Bollu --- easy_my_coop_website/controllers/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/easy_my_coop_website/controllers/main.py b/easy_my_coop_website/controllers/main.py index 960c010..3976d57 100644 --- a/easy_my_coop_website/controllers/main.py +++ b/easy_my_coop_website/controllers/main.py @@ -331,6 +331,9 @@ class WebsiteSubscription(http.Controller): ) return request.render(redirect, values) + # There's no issue with the email, so we can remember the confirmation email + values["confirm_email"] = email + company = request.website.company_id if company.allow_id_card_upload: if not post_file: From 6bf86567d9a8a8f301fda6695e131c6da8794c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Sun, 15 Nov 2020 21:48:19 +0100 Subject: [PATCH 3/4] [FIX] C901 flake8 --- .flake8 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 2cac7e9..a0f043a 100644 --- a/.flake8 +++ b/.flake8 @@ -7,4 +7,5 @@ select = C,E,F,W,B,B9 # E203: whitespace before ':' (black behaviour) # E501: flake8 line length (covered by bugbear B950) # W503: line break before binary operator (black behaviour) -ignore = E203,E501,W503 +# C901: Function is too complex +ignore = E203,E501,W503,C901 From 578208e1e99ed086318c1bf439e39eef6df18174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Sun, 15 Nov 2020 21:49:04 +0100 Subject: [PATCH 4/4] [FIX] Linting --- easy_my_coop_website/controllers/main.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/easy_my_coop_website/controllers/main.py b/easy_my_coop_website/controllers/main.py index 3976d57..33db630 100644 --- a/easy_my_coop_website/controllers/main.py +++ b/easy_my_coop_website/controllers/main.py @@ -7,16 +7,10 @@ from odoo.http import request from odoo.tools.translate import _ # Only use for behavior, don't stock it -_TECHNICAL = [ - "view_from", - "view_callback" -] +_TECHNICAL = ["view_from", "view_callback"] # transient fields used to compute the address field -_EXTRA_FIELDS = [ - "street_name", - "house_number" -] +_EXTRA_FIELDS = ["street_name", "house_number"] # Allow in description _BLACKLIST = [ @@ -268,7 +262,7 @@ class WebsiteSubscription(http.Controller): redirect = "easy_my_coop_website.becomecompanycooperator" email = kwargs.get("company_email") # TODO: Use a overloaded function with the captcha implementation - if request.website.company_id.captcha_type == 'google': + if request.website.company_id.captcha_type == "google": if ( "g-recaptcha-response" not in kwargs or kwargs["g-recaptcha-response"] == "" @@ -422,10 +416,7 @@ class WebsiteSubscription(http.Controller): and field_name not in _BLACKLIST ): values[field_name] = field_value - elif ( - field_name in _EXTRA_FIELDS - and field_name not in _BLACKLIST - ): + elif field_name in _EXTRA_FIELDS and field_name not in _BLACKLIST: values[field_name] = field_value # allow to add some free fields or blacklisted field like ID elif field_name not in _TECHNICAL: @@ -470,7 +461,10 @@ class WebsiteSubscription(http.Controller): values["share_product_id"] = self.get_selected_share(kwargs).id - values["address"] = kwargs.get("street_name") + ", " + kwargs.get("house_number") + values["address"] = "{street}, {number}".format( + street=kwargs.get("street_name", ""), + number=kwargs.get("house_number", ""), + ) del values["street_name"] del values["house_number"]