summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpa-odoo <jpa@openerp.com>2015-01-26 14:09:50 +0100
committerJérome Maes <jem@openerp.com>2015-01-30 17:05:13 +0100
commitef198302b71a9975dc0c1fc3546e4e626d8472cd (patch)
tree37511c802e5266f022e6ce7f63e5b315bd4a7bb3
parent1903e89e0dcef34c3a3744ec7c07a10dcd152779 (diff)
[IMP] website_sale : in billing step form, display error message. Remove inline css and validate email.
-rw-r--r--addons/website_sale/controllers/main.py19
-rw-r--r--addons/website_sale/static/src/css/website_sale.css5
-rw-r--r--addons/website_sale/static/src/css/website_sale.sass4
-rw-r--r--addons/website_sale/views/templates.xml17
4 files changed, 35 insertions, 10 deletions
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py
index bf28cfbee6b..e7ed3158695 100644
--- a/addons/website_sale/controllers/main.py
+++ b/addons/website_sale/controllers/main.py
@@ -3,6 +3,7 @@ import werkzeug
from openerp import SUPERUSER_ID
from openerp import http
+from openerp import tools
from openerp.http import request
from openerp.tools.translate import _
from openerp.addons.website.models.website import slug
@@ -509,12 +510,20 @@ class website_sale(http.Controller):
def checkout_form_validate(self, data):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
- # Validation
error = dict()
+ error_message = []
+
+ # Validation
for field_name in self.mandatory_billing_fields:
if not data.get(field_name):
error[field_name] = 'missing'
+ # email validation
+ if data.get('email') and not tools.single_email_re.match(data.get('email')):
+ error["email"] = 'error'
+ error_message.append(_('Invalid Email! Please enter a valid email address.'))
+
+ # vat validation
if data.get("vat") and hasattr(registry["res.partner"], "check_vat"):
if request.website.company_id.vat_check_vies:
# force full VIES online check
@@ -532,7 +541,11 @@ class website_sale(http.Controller):
if not data.get(field_name):
error[field_name] = 'missing'
- return error
+ # error message for empty required fields
+ if [err for err in error.values() if err == 'missing']:
+ error_message.append(_('Some required fields are empty.'))
+
+ return error, error_message
def checkout_form_save(self, checkout):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
@@ -624,7 +637,7 @@ class website_sale(http.Controller):
values = self.checkout_values(post)
- values["error"] = self.checkout_form_validate(values["checkout"])
+ values["error"], values["error_message"] = self.checkout_form_validate(values["checkout"])
if values["error"]:
return request.website.render("website_sale.checkout", values)
diff --git a/addons/website_sale/static/src/css/website_sale.css b/addons/website_sale/static/src/css/website_sale.css
index 24af7d36087..9cf135a66b5 100644
--- a/addons/website_sale/static/src/css/website_sale.css
+++ b/addons/website_sale/static/src/css/website_sale.css
@@ -352,4 +352,7 @@ ul.wizard li:first-child {
padding-left: 15px;
border-radius: 4px 0 0 4px; }
-/*# sourceMappingURL=website_sale.css.map */
+/* Shipping & Billing */
+.label-optional {
+ font-weight: normal;
+}
diff --git a/addons/website_sale/static/src/css/website_sale.sass b/addons/website_sale/static/src/css/website_sale.sass
index 598baf7cee6..8c5abcfa4d0 100644
--- a/addons/website_sale/static/src/css/website_sale.sass
+++ b/addons/website_sale/static/src/css/website_sale.sass
@@ -385,3 +385,7 @@ ul.wizard li.text-primary .chevron:before
ul.wizard li:first-child
padding-left: 15px
border-radius: 4px 0 0 4px
+
+/* Shipping & Billing */
+.label-optional
+ font-weight: normal
diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml
index f5d128b8392..8e0d128190e 100644
--- a/addons/website_sale/views/templates.xml
+++ b/addons/website_sale/views/templates.xml
@@ -781,17 +781,22 @@
</small>
</h3>
<div class="row">
+ <div class="col-md-12">
+ <div t-if="error_message" class="alert alert-danger">
+ <t t-foreach="error_message" t-as="err"><t t-esc="err"/><br /></t>
+ </div>
+ </div>
<div t-attf-class="form-group #{error.get('name') and 'has-error' or ''} col-lg-6">
<label class="control-label" for="contact_name">Your Name</label>
<input type="text" name="name" class="form-control" t-att-value="checkout.get('name')"/>
</div>
<div t-if="has_check_vat" class="clearfix"/>
<div t-attf-class="form-group #{error.get('street') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="street" style="font-weight: normal">Company Name</label>
+ <label class="control-label label-optional" for="street">Company Name</label>
<input type="text" name="street" class="form-control" t-att-value="checkout.get('street')"/>
</div>
<div t-if="has_check_vat" t-attf-class="form-group #{error.get('vat') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="vat" style="font-weight: normal">VAT Number</label>
+ <label class="control-label label-optional" for="vat">VAT Number</label>
<input type="text" name="vat" class="form-control" t-att-value="checkout.get('vat')"/>
</div>
<div t-attf-class="form-group #{error.get('email') and 'has-error' or ''} col-lg-6">
@@ -814,7 +819,7 @@
<input type="text" name="city" class="form-control" t-att-value="checkout.get('city')"/>
</div>
<div t-attf-class="form-group #{error.get('zip') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="zip" style="font-weight: normal">Zip / Postal Code</label>
+ <label class="control-label label-optional" for="zip">Zip / Postal Code</label>
<input type="text" name="zip" class="form-control" t-att-value="checkout.get('zip')"/>
</div>
<div t-attf-class="form-group #{error.get('country_id') and 'has-error' or ''} col-lg-6">
@@ -827,7 +832,7 @@
</select>
</div>
<div t-attf-class="form-group #{error.get('state_id') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="state_id" style="font-weight: normal">State / Province</label>
+ <label class="control-label label-optional" for="state_id">State / Province</label>
<select name="state_id" class="form-control">
<option value="">select...</option>
<t t-foreach="states or []" t-as="state">
@@ -878,7 +883,7 @@
<input type="text" name="shipping_city" class="form-control" t-att-value="checkout.get('shipping_city', '')" t-att-readonly=" 'readonly' if shipping_id &gt;= 0 else ''"/>
</div>
<div t-attf-class="form-group #{error.get('shipping_zip') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="shipping_zip" style="font-weight: normal">Zip / Postal Code</label>
+ <label class="control-label label-optional" for="shipping_zip">Zip / Postal Code</label>
<input type="text" name="shipping_zip" class="form-control" t-att-value="checkout.get('shipping_zip', '')" t-att-readonly=" 'readonly' if shipping_id &gt;= 0 else ''"/>
</div>
<div t-attf-class="form-group #{error.get('shipping_country_id') and 'has-error' or ''} col-lg-6">
@@ -891,7 +896,7 @@
</select>
</div>
<div t-attf-class="form-group #{error.get('shipping_state_id') and 'has-error' or ''} col-lg-6">
- <label class="control-label" for="shipping_state_id" style="font-weight: normal">State / Province</label>
+ <label class="control-label label-optional" for="shipping_state_id">State / Province</label>
<select name="shipping_state_id" class="form-control" t-att-readonly=" 'readonly' if shipping_id &gt;= 0 else ''">
<option value="">State / Province...</option>
<t t-foreach="states or []" t-as="state">