[FIX] website_sale: checkout: do not reset address country every time
authorOlivier Dony <odo@openerp.com>
Tue, 30 Sep 2014 15:54:25 +0000 (17:54 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 1 Oct 2014 13:16:00 +0000 (15:16 +0200)
Once the value is set it can be modified by the user
(e.g. if geoip detection was wrong), so should not be reset.

addons/website_sale/controllers/main.py

index 774024f..b43ac55 100644 (file)
@@ -406,11 +406,12 @@ class website_sale(http.Controller):
         checkout['shipping_id'] = shipping_id
 
         # Default search by user country
-        country_code = request.session['geoip'].get('country_code')
-        if country_code:
-            country_ids = request.registry.get('res.country').search(cr, uid, [('code', '=', country_code)], context=context)
-            if country_ids:
-                checkout['country_id'] = country_ids[0]
+        if not checkout.get('country_id'):
+            country_code = request.session['geoip'].get('country_code')
+            if country_code:
+                country_ids = request.registry.get('res.country').search(cr, uid, [('code', '=', country_code)], context=context)
+                if country_ids:
+                    checkout['country_id'] = country_ids[0]
 
         values = {
             'countries': countries,