[IMP] res_partner: added a hook to be sure the website is correctly formated.

Otherwise the website may consider the website field as local for address like
www.odoo.com
This commit is contained in:
Thibault Delavallée 2014-05-16 16:09:27 +02:00
parent 3ca44e9324
commit 726fad8832
1 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import datetime
from lxml import etree
import math
import pytz
import urlparse
import openerp
from openerp import SUPERUSER_ID
@ -507,6 +508,14 @@ class res_partner(osv.osv, format_address):
if not parent.is_company:
parent.write({'is_company': True})
def _clean_website(self, website):
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(website)
if not scheme:
if not netloc:
netloc, path = path, ''
website = urlparse.urlunparse(('http', netloc, path, params, query, fragment))
return website
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
@ -514,6 +523,8 @@ class res_partner(osv.osv, format_address):
#is the same as the company of all users that inherit from this partner
#(this is to allow the code from res_users to write to the partner!) or
#if setting the company_id to False (this is compatible with any user company)
if vals.get('website'):
vals['website'] = self._clean_website(vals['website'])
if vals.get('company_id'):
for partner in self.browse(cr, uid, ids, context=context):
if partner.user_ids:
@ -526,6 +537,8 @@ class res_partner(osv.osv, format_address):
return result
def create(self, cr, uid, vals, context=None):
if vals.get('website'):
vals['website'] = self._clean_website(vals['website'])
new_id = super(res_partner, self).create(cr, uid, vals, context=context)
partner = self.browse(cr, uid, new_id, context=context)
self._fields_sync(cr, uid, partner, vals, context)