Browse Source

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.
pull/114/head
Cyrille Bollu 4 years ago
parent
commit
a70dbfd6c6
  1. 5
      easy_my_coop/models/coop.py
  2. 27
      easy_my_coop_website/controllers/main.py
  3. 64
      easy_my_coop_website/views/subscription_template.xml

5
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()

27
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(

64
easy_my_coop_website/views/subscription_template.xml

@ -256,18 +256,34 @@
style="margin-left:25%;margin-top:35px;width:59%"></div>
</div>
<div t-attf-class="form-group #{error and 'address' in error and 'has-error' or ''}">
<div t-attf-class="form-group #{error and 'house_number' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label"
for="address">Address
for="house_number">Address
</label>
<div class="col-md-7 col-sm-8">
<input type="text"
class="form-control mandatory-field"
name="address"
required="True"
t-att-readonly="logged"
t-attf-value="#{address or ''}"
placeholder="rue Van Hove, 19"/>
<table>
<tr>
<td width="15%">
<input type="text"
class="form-control mandatory-field"
name="house_number"
required="True"
t-att-readonly="logged"
t-attf-value="#{house_number or ''}"
placeholder="19"/>
</td>
<td width="3%"></td>
<td>
<input type="text"
class="form-control mandatory-field"
name="street_name"
required="True"
t-att-readonly="logged"
t-attf-value="#{street_name or ''}"
placeholder="rue Van Hove"/>
</td>
</tr>
</table>
</div>
</div>
@ -650,13 +666,29 @@
for="address">Address
</label>
<div class="col-md-7 col-sm-8">
<input type="text"
class="form-control mandatory-field"
name="address"
required="True"
t-att-readonly="logged"
t-attf-value="#{address or ''}"
placeholder="rue Van Hove, 19"/>
<table>
<tr>
<td width="15%">
<input type="text"
class="form-control mandatory-field"
name="house_number"
required="True"
t-att-readonly="logged"
t-attf-value="#{street_number or ''}"
placeholder="19"/>
</td>
<td width="3%"></td>
<td>
<input type="text"
class="form-control mandatory-field"
name="street_name"
required="True"
t-att-readonly="logged"
t-attf-value="#{street_name or ''}"
placeholder="rue Van Hove"/>
</td>
</tr>
</table>
</div>
</div>

Loading…
Cancel
Save