[FIX][IMP] base: partner image

Do not compute the partner default image when being in testing or install mode.
For example when importing a huge list of contacts there is no need to compute
a default image for every contact.

Moreover the random colorize is more limited. There is no need to explore the
whole space of rgb. It is now limited by steps in the rgb random, leading to
less different images being possible. There are currently 512 possible
combinaisons.
This commit is contained in:
Thibault Delavallée
2016-01-11 17:47:44 +01:00
parent db638d8b33
commit 929e060c07
2 changed files with 6 additions and 2 deletions
+4
View File
@@ -5,6 +5,7 @@ import datetime
from lxml import etree
import math
import pytz
import threading
import urlparse
import openerp
@@ -303,6 +304,9 @@ class res_partner(osv.Model, format_address):
@api.model
def _get_default_image(self, is_company, colorize=False):
if getattr(threading.currentThread(), 'testing', False) or self.env.context.get('install_mode'):
return False
img_path = openerp.modules.get_module_resource(
'base', 'static/src/img', 'company_image.png' if is_company else 'avatar.png')
with open(img_path, 'rb') as f:
+2 -2
View File
@@ -8,7 +8,7 @@ except ImportError:
from PIL import Image
from PIL import ImageEnhance
from random import randint
from random import randrange
# ----------------------------------------
# Image resizing
@@ -213,7 +213,7 @@ def image_colorize(original, randomize=True, color=(255, 255, 255)):
image = Image.new('RGB', original.size)
# generate the background color, past it as background
if randomize:
color = (randint(32, 224), randint(32, 224), randint(32, 224))
color = (randrange(32, 224, 24), randrange(32, 224, 24), randrange(32, 224, 24))
image.paste(color)
image.paste(original, mask=original)
# return the new image