[IMP] website_sale : in billing step form, display error message. Remove inline css and validate email.

This commit is contained in:
jpa-odoo
2015-01-30 17:05:13 +01:00
committed by Jérome Maes
parent 1903e89e0d
commit ef198302b7
4 changed files with 35 additions and 10 deletions
+16 -3
View File
@@ -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)
@@ -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;
}
@@ -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
+11 -6
View File
@@ -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">