From a70dbfd6c640a27c46bb1cbf57a9967b694bccf6 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Tue, 11 Aug 2020 15:49:27 +0200 Subject: [PATCH] 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
- + + + + + + +
+ + + +