summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Zanotti (ADHOC) <bz@adhoc.com.ar>2020-10-19 17:20:43 +0000
committerBruno Zanotti (ADHOC) <bz@adhoc.com.ar>2021-04-06 15:14:47 +0000
commit3b01c249a8d2b9673992942c2c5ea50ef0488708 (patch)
tree9d80fde8702e1ef2da4c9101f9e11b7992f96e76
parente23b9bfd47b2a8aee4468fdd3f35aced81761eb3 (diff)
[IMP] website_sale: small refactor to adapt the module to the inheritance of the localizations
* New method _get_vat_validation_fields to set the fields used in vat validation. * New method _get_country_related_render_values that returns all the fields related to the country to be rendered in the address form. These methods are necessary to allow the different localizations (see l10n_ar_website_sale) to adapt the ecommerce to their own needs. closes odoo/odoo#60309 Signed-off-by: Josse Colpaert <jco@openerp.com>
-rw-r--r--addons/website_sale/controllers/main.py53
1 files changed, 37 insertions, 16 deletions
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py
index ba55d540866..8495170c790 100644
--- a/addons/website_sale/controllers/main.py
+++ b/addons/website_sale/controllers/main.py
@@ -591,20 +591,24 @@ class WebsiteSale(http.Controller):
if data.get("vat") and hasattr(Partner, "check_vat"):
if country_id:
data["vat"] = Partner.fix_eu_vat_number(country_id, data.get("vat"))
- partner_dummy = Partner.new({
- 'vat': data['vat'],
- 'country_id': country_id or False,
- })
+ partner_dummy = Partner.new(self._get_vat_validation_fields(data))
try:
partner_dummy.check_vat()
- except ValidationError:
+ except ValidationError as exception:
error["vat"] = 'error'
+ error_message.append(exception.args[0])
if [err for err in error.values() if err == 'missing']:
error_message.append(_('Some required fields are empty.'))
return error, error_message
+ def _get_vat_validation_fields(self, data):
+ return {
+ 'vat': data['vat'],
+ 'country_id': int(data['country_id']) if data.get('country_id') else False,
+ }
+
def _checkout_form_save(self, mode, checkout, all_values):
Partner = request.env['res.partner']
if mode[0] == 'new':
@@ -670,7 +674,6 @@ class WebsiteSale(http.Controller):
mode = (False, False)
can_edit_vat = False
- def_country_id = order.partner_id.country_id
values, errors = {}, {}
partner_id = int(kw.get('partner_id', -1))
@@ -679,11 +682,6 @@ class WebsiteSale(http.Controller):
if order.partner_id.id == request.website.user_id.sudo().partner_id.id:
mode = ('new', 'billing')
can_edit_vat = True
- country_code = request.session['geoip'].get('country_code')
- if country_code:
- def_country_id = request.env['res.country'].search([('code', '=', country_code)], limit=1)
- else:
- def_country_id = request.website.user_id.sudo().country_id
# IF ORDER LINKED TO A PARTNER
else:
if partner_id > 0:
@@ -733,23 +731,46 @@ class WebsiteSale(http.Controller):
if not errors:
return request.redirect(kw.get('callback') or '/shop/confirm_order')
- country = 'country_id' in values and values['country_id'] != '' and request.env['res.country'].browse(int(values['country_id']))
- country = country and country.exists() or def_country_id
render_values = {
'website_sale_order': order,
'partner_id': partner_id,
'mode': mode,
'checkout': values,
'can_edit_vat': can_edit_vat,
- 'country': country,
- 'country_states': country.get_website_sale_states(mode=mode[1]),
- 'countries': country.get_website_sale_countries(mode=mode[1]),
'error': errors,
'callback': kw.get('callback'),
'only_services': order and order.only_services,
}
+ render_values.update(self._get_country_related_render_values(kw, render_values))
return request.render("website_sale.address", render_values)
+ def _get_country_related_render_values(self, kw, render_values):
+ '''
+ This method provides fields related to the country to render the website sale form
+ '''
+ values = render_values['checkout']
+ mode = render_values['mode']
+ order = render_values['website_sale_order']
+
+ def_country_id = order.partner_id.country_id
+ # IF PUBLIC ORDER
+ if order.partner_id.id == request.website.user_id.sudo().partner_id.id:
+ country_code = request.session['geoip'].get('country_code')
+ if country_code:
+ def_country_id = request.env['res.country'].search([('code', '=', country_code)], limit=1)
+ else:
+ def_country_id = request.website.user_id.sudo().country_id
+
+ country = 'country_id' in values and values['country_id'] != '' and request.env['res.country'].browse(int(values['country_id']))
+ country = country and country.exists() or def_country_id
+
+ res = {
+ 'country': country,
+ 'country_states': country.get_website_sale_states(mode=mode[1]),
+ 'countries': country.get_website_sale_countries(mode=mode[1]),
+ }
+ return res
+
@http.route(['/shop/checkout'], type='http', auth="public", website=True, sitemap=False)
def checkout(self, **post):
order = request.website.sale_get_order()