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 diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index d3fe1f2..b4d494d 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -10,12 +10,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", @@ -36,6 +38,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 f9ef8fa..310dfbc 100644 --- a/easy_my_coop_website/controllers/main.py +++ b/easy_my_coop_website/controllers/main.py @@ -8,6 +8,10 @@ from odoo.tools.translate import _ # Only use for behavior, don't stock it _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 +31,8 @@ _COOP_FORM_FIELD = [ "birthdate", "iban", "share_product_id", - "address", + "street_name", + "house_number", "city", "zip_code", "country_id", @@ -50,7 +55,8 @@ _COMPANY_FORM_FIELD = [ "birthdate", "iban", "share_product_id", - "address", + "street_name", + "house_number", "city", "zip_code", "country_id", @@ -324,6 +330,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: @@ -412,6 +421,8 @@ 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( @@ -458,6 +469,13 @@ class WebsiteSubscription(http.Controller): values["share_product_id"] = self.get_selected_share(kwargs).id + values["address"] = "{street}, {number}".format( + street=kwargs.get("street_name", ""), + number=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 8e3d4a1..6345df1 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%"> -
+
- + + + + + + +
+ + + +
@@ -675,13 +691,29 @@ for="address">Address
- + + + + + + +
+ + + +