[FIX] website_sale: make checkout fields customizable
[FIX] Valuable checkout hooks for website_sale [FIX] Values might need to be changed for different field mappings [FIX] Make definition of form fields inheritable within a function [FIX] Make shipping_info values available for inherited module manipulation Close #8490
This commit is contained in:
parent
dbddc8246a
commit
4f41c3327c
|
@ -463,16 +463,31 @@ class website_sale(http.Controller):
|
||||||
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id"]
|
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id"]
|
||||||
optional_shipping_fields = ["state_id", "zip"]
|
optional_shipping_fields = ["state_id", "zip"]
|
||||||
|
|
||||||
|
def _get_mandatory_billing_fields(self):
|
||||||
|
return self.mandatory_billing_fields
|
||||||
|
|
||||||
|
def _get_optional_billing_fields(self):
|
||||||
|
return self.optional_billing_fields
|
||||||
|
|
||||||
|
def _get_mandatory_shipping_fields(self):
|
||||||
|
return self.mandatory_shipping_fields
|
||||||
|
|
||||||
|
def _get_optional_shipping_fields(self):
|
||||||
|
return self.optional_shipping_fields
|
||||||
|
|
||||||
|
def _post_prepare_query(self, query, data, address_type):
|
||||||
|
return query
|
||||||
|
|
||||||
def checkout_parse(self, address_type, data, remove_prefix=False):
|
def checkout_parse(self, address_type, data, remove_prefix=False):
|
||||||
""" data is a dict OR a partner browse record
|
""" data is a dict OR a partner browse record
|
||||||
"""
|
"""
|
||||||
# set mandatory and optional fields
|
# set mandatory and optional fields
|
||||||
assert address_type in ('billing', 'shipping')
|
assert address_type in ('billing', 'shipping')
|
||||||
if address_type == 'billing':
|
if address_type == 'billing':
|
||||||
all_fields = self.mandatory_billing_fields + self.optional_billing_fields
|
all_fields = self._get_mandatory_billing_fields() + self._get_optional_billing_fields()
|
||||||
prefix = ''
|
prefix = ''
|
||||||
else:
|
else:
|
||||||
all_fields = self.mandatory_shipping_fields + self.optional_shipping_fields
|
all_fields = self._get_mandatory_shipping_fields() + self._get_optional_shipping_fields()
|
||||||
prefix = 'shipping_'
|
prefix = 'shipping_'
|
||||||
|
|
||||||
# set data
|
# set data
|
||||||
|
@ -493,6 +508,8 @@ class website_sale(http.Controller):
|
||||||
if query.get(prefix + 'vat'):
|
if query.get(prefix + 'vat'):
|
||||||
query[prefix + 'vat_subjected'] = True
|
query[prefix + 'vat_subjected'] = True
|
||||||
|
|
||||||
|
query = self._post_prepare_query(query, data, address_type)
|
||||||
|
|
||||||
if not remove_prefix:
|
if not remove_prefix:
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
@ -503,7 +520,7 @@ class website_sale(http.Controller):
|
||||||
|
|
||||||
# Validation
|
# Validation
|
||||||
error = dict()
|
error = dict()
|
||||||
for field_name in self.mandatory_billing_fields:
|
for field_name in self._get_mandatory_billing_fields():
|
||||||
if not data.get(field_name):
|
if not data.get(field_name):
|
||||||
error[field_name] = 'missing'
|
error[field_name] = 'missing'
|
||||||
|
|
||||||
|
@ -519,13 +536,19 @@ class website_sale(http.Controller):
|
||||||
error["vat"] = 'error'
|
error["vat"] = 'error'
|
||||||
|
|
||||||
if data.get("shipping_id") == -1:
|
if data.get("shipping_id") == -1:
|
||||||
for field_name in self.mandatory_shipping_fields:
|
for field_name in self._get_mandatory_shipping_fields():
|
||||||
field_name = 'shipping_' + field_name
|
field_name = 'shipping_' + field_name
|
||||||
if not data.get(field_name):
|
if not data.get(field_name):
|
||||||
error[field_name] = 'missing'
|
error[field_name] = 'missing'
|
||||||
|
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
def _get_shipping_info(self, checkout):
|
||||||
|
shipping_info = {}
|
||||||
|
shipping_info.update(self.checkout_parse('shipping', checkout, True))
|
||||||
|
shipping_info['type'] = 'delivery'
|
||||||
|
return shipping_info
|
||||||
|
|
||||||
def checkout_form_save(self, checkout):
|
def checkout_form_save(self, checkout):
|
||||||
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
|
||||||
|
|
||||||
|
@ -561,11 +584,9 @@ class website_sale(http.Controller):
|
||||||
|
|
||||||
# create a new shipping partner
|
# create a new shipping partner
|
||||||
if checkout.get('shipping_id') == -1:
|
if checkout.get('shipping_id') == -1:
|
||||||
shipping_info = {}
|
shipping_info = self._get_shipping_info(checkout)
|
||||||
if partner_lang:
|
if partner_lang:
|
||||||
shipping_info['lang'] = partner_lang
|
shipping_info['lang'] = partner_lang
|
||||||
shipping_info.update(self.checkout_parse('shipping', checkout, True))
|
|
||||||
shipping_info['type'] = 'delivery'
|
|
||||||
shipping_info['parent_id'] = partner_id
|
shipping_info['parent_id'] = partner_id
|
||||||
checkout['shipping_id'] = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
|
checkout['shipping_id'] = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue