[FIX] base: restore _clean_website on res.partner

Commit d5d2c5524c improved the UrlWidget s.t. it automatically
prefixes the url with 'http://' if no protocol is specified (except
for own website paths).

In addition, it removed a logic specific to model res.partner that
automatically prefixes the saved website values with 'http://'.

However, the second part should not have been done: those urls can
be displayed without UrlWidget (e.g. on the website), and in this
case, the protocol wouldn't be set, meaning that it would behave
like a relative link.

closes odoo/odoo#52113

X-original-commit: 5a8690bb64cb3dc01ee8d4f9af3a6ab91eee8b99
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Aaron Bohy
2020-05-28 14:30:57 +00:00
parent 98d1c55090
commit c8f4098a51
+12
View File
@@ -495,6 +495,14 @@ class Partner(models.Model):
addr_vals = self._update_fields_values(address_fields)
parent.update_address(addr_vals)
def _clean_website(self, website):
url = urls.url_parse(website)
if not url.scheme:
if not url.netloc:
url = url.replace(netloc=url.path, path='')
website = url.replace(scheme='http').to_url()
return website
def write(self, vals):
if vals.get('active') is False:
# DLE: It should not be necessary to modify this to make work the ORM. The problem was just the recompute
@@ -514,6 +522,8 @@ class Partner(models.Model):
# (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('parent_id'):
vals['company_name'] = False
if vals.get('company_id'):
@@ -543,6 +553,8 @@ class Partner(models.Model):
if self.env.context.get('import_file'):
self._check_import_consistency(vals_list)
for vals in vals_list:
if vals.get('website'):
vals['website'] = self._clean_website(vals['website'])
if vals.get('parent_id'):
vals['company_name'] = False
partners = super(Partner, self).create(vals_list)