From f10f120de3017bc8d0e9a5ac72eeec1280374a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 26 Aug 2019 15:50:28 +0000 Subject: [PATCH] [IMP] base: remove default image from res.partner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Processing the default image takes too much time. Creating 1000 partners without image takes around: - 7s before this commit - 1.5s after this commit Moreover by saving the default image it's impossible to tell which partners have a default image and which have an actual image. After this commit, the views should handle displaying a placeholder when no image is set, which is already the case since the default image could already be missing if it was removed from `write`. closes odoo/odoo#36093 Signed-off-by: Sébastien Theys (seb) --- odoo/addons/base/models/res_partner.py | 33 -------------------------- 1 file changed, 33 deletions(-) diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 629f27d2558..7be6deab206 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -309,35 +309,6 @@ class Partner(models.Model): p = partner.commercial_partner_id partner.commercial_company_name = p.is_company and p.name or partner.company_name - @api.model - def _get_default_image(self, partner_type, is_company, parent_id): - if getattr(threading.currentThread(), 'testing', False) or self._context.get('install_mode'): - return False - - colorize, img_path, image_base64 = False, False, False - - if partner_type in ['other'] and parent_id: - parent_image = self.browse(parent_id).image_1920 - image_base64 = parent_image or None - - if not image_base64 and partner_type == 'invoice': - img_path = get_module_resource('base', 'static/img', 'money.png') - elif not image_base64 and partner_type == 'delivery': - img_path = get_module_resource('base', 'static/img', 'truck.png') - elif not image_base64 and is_company: - img_path = get_module_resource('base', 'static/img', 'company_image.png') - elif not image_base64: - img_path = get_module_resource('base', 'static/img', 'avatar.png') - colorize = True - - if img_path: - with open(img_path, 'rb') as f: - image_base64 = base64.b64encode(f.read()) - if image_base64 and colorize: - image_base64 = tools.image_process(image_base64, colorize=True) - - return image_base64 - @api.model def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): if (not view_id) and (view_type == 'form') and self._context.get('force_email'): @@ -586,10 +557,6 @@ class Partner(models.Model): vals['website'] = self._clean_website(vals['website']) if vals.get('parent_id'): vals['company_name'] = False - # compute default image in create, because computing gravatar in the onchange - # cannot be easily performed if default images are in the way - if not vals.get('image_1920'): - vals['image_1920'] = self._get_default_image(vals.get('type'), vals.get('is_company'), vals.get('parent_id')) partners = super(Partner, self).create(vals_list) if self.env.context.get('_partners_skip_fields_sync'):