- def write(self, cr, uid, ids, vals, context=None):
- if isinstance(ids, (int, long)):
- ids = [ids]
- #res.partner must only allow to set the company_id of a partner if it
- #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)
+ def unlink(self, cr, uid, ids, context=None):
+ orphan_contact_ids = self.search(cr, uid,
+ [('parent_id', 'in', ids), ('id', 'not in', ids), ('use_parent_address', '=', True)], context=context)
+ if orphan_contact_ids:
+ # no longer have a parent address
+ self.write(cr, uid, orphan_contact_ids, {'use_parent_address': False}, context=context)
+ return super(res_partner, self).unlink(cr, uid, ids, context=context)
+
+ 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
+
+ @api.multi
+ def write(self, vals):
+ # res.partner must only allow to set the company_id of a partner if it
+ # 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'])