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 import _, api, fields, models
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
# This structure is only used in easy_my_coop_webstite's controller
_REQUIRED = [ _REQUIRED = [
"email", "email",
"firstname", "firstname",
"lastname", "lastname",
"birthdate", "birthdate",
"address",
"street_name",
"house_number",
"share_product_id", "share_product_id",
"ordered_parts", "ordered_parts",
"zip_code", "zip_code",
@ -37,6 +39,7 @@ class SubscriptionRequest(models.Model):
_name = "subscription.request" _name = "subscription.request"
_description = "Subscription Request" _description = "Subscription Request"
# This function is only used in easy_my_coop_webstite's controller
def get_required_field(self): def get_required_field(self):
required_fields = _REQUIRED required_fields = _REQUIRED
company = self.env["res.company"]._company_default_get() 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 _ from odoo.tools.translate import _
# Only use for behavior, don't stock it # 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 # Allow in description
_BLACKLIST = [ _BLACKLIST = [
"id", "id",
@ -27,7 +37,8 @@ _COOP_FORM_FIELD = [
"birthdate", "birthdate",
"iban", "iban",
"share_product_id", "share_product_id",
"address",
"street_name",
"house_number",
"city", "city",
"zip_code", "zip_code",
"country_id", "country_id",
@ -50,7 +61,8 @@ _COMPANY_FORM_FIELD = [
"birthdate", "birthdate",
"iban", "iban",
"share_product_id", "share_product_id",
"address",
"street_name",
"house_number",
"city", "city",
"zip_code", "zip_code",
"country_id", "country_id",
@ -407,6 +419,11 @@ class WebsiteSubscription(http.Controller):
and field_name not in _BLACKLIST and field_name not in _BLACKLIST
): ):
values[field_name] = field_value 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 # allow to add some free fields or blacklisted field like ID
elif field_name not in _TECHNICAL: elif field_name not in _TECHNICAL:
post_description.append( post_description.append(
@ -450,6 +467,10 @@ class WebsiteSubscription(http.Controller):
values["share_product_id"] = self.get_selected_share(kwargs).id 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 is_company:
if kwargs.get("company_register_number", is_company): if kwargs.get("company_register_number", is_company):
values["company_register_number"] = re.sub( 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> style="margin-left:25%;margin-top:35px;width:59%"></div>
</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" <label class="col-md-3 col-sm-4 control-label"
for="address">Address
for="house_number">Address
</label> </label>
<div class="col-md-7 col-sm-8"> <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>
</div> </div>
@ -650,13 +666,29 @@
for="address">Address for="address">Address
</label> </label>
<div class="col-md-7 col-sm-8"> <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>
</div> </div>

Loading…
Cancel
Save