Skip to content
Permalink
Browse files

[IMP] tools,base,*: remove intermediary image tools

* = hr, im_livechat, mail, payment, purchase, web, web_editor, web_unsplash,
	website_profile, website_slides
  • Loading branch information...
seb-odoo committed Mar 20, 2019
1 parent 0d24f78 commit c913e150b982adcf30b9f0bd382af9947e7e3b72
@@ -106,7 +106,7 @@ class Employee(models.Model):
@api.model
def _default_image(self):
image_path = get_module_resource('hr', 'static/src/img', 'default_image.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
return tools.image_process(base64.b64encode(open(image_path, 'rb').read()), size=tools.IMAGE_BIG_SIZE)

# resource and user
# required on the resource, make sure required="True" set in the view
@@ -21,7 +21,7 @@ class ImLivechatChannel(models.Model):

def _default_image(self):
image_path = modules.get_module_resource('im_livechat', 'static/src/img', 'default.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
return tools.image_process(base64.b64encode(open(image_path, 'rb').read()), size=tools.IMAGE_BIG_SIZE)

def _default_user_ids(self):
return [(6, 0, [self._uid])]
@@ -64,7 +64,7 @@ class Channel(models.Model):

def _get_default_image(self):
image_path = modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
return tools.image_process(base64.b64encode(open(image_path, 'rb').read()), size=tools.IMAGE_BIG_SIZE)

@api.model
def default_get(self, fields):
@@ -7,11 +7,10 @@
from dateutil import relativedelta
import pprint

from odoo import api, exceptions, fields, models, _
from odoo.tools import consteq, float_round, image_resize_images, image_resize_image, ustr
from odoo import api, exceptions, fields, models, _, SUPERUSER_ID
from odoo.tools import consteq, float_round, image_resize_images, image_process, ustr
from odoo.addons.base.models import ir_module
from odoo.exceptions import ValidationError
from odoo import api, SUPERUSER_ID
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools.misc import formatLang

@@ -512,16 +511,16 @@ def create(self, vals_list):
for vals in vals_list:
if 'image' in vals:
image = ustr(vals['image'] or '').encode('utf-8')
vals['image_payment_form'] = image_resize_image(image, size=(45,30))
vals['image'] = image_resize_image(image, size=(64,64))
vals['image_payment_form'] = image_process(image, size=(45,30))
vals['image'] = image_process(image, size=(64,64))
return super(PaymentIcon, self).create(vals_list)

@api.multi
def write(self, vals):
if 'image' in vals:
image = ustr(vals['image'] or '').encode('utf-8')
vals['image_payment_form'] = image_resize_image(image, size=(45,30))
vals['image'] = image_resize_image(image, size=(64,64))
vals['image_payment_form'] = image_process(image, size=(45,30))
vals['image'] = image_process(image, size=(64,64))
return super(PaymentIcon, self).write(vals)

class PaymentTransaction(models.Model):
@@ -7,7 +7,7 @@
from odoo import http
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.tools import image_resize_image
from odoo.tools import image_process
from odoo.tools.translate import _
from odoo.addons.portal.controllers.portal import pager as portal_pager, CustomerPortal
from odoo.addons.web.controllers.main import Binary
@@ -28,7 +28,7 @@ def _purchase_order_get_page_view_values(self, order, access_token, **kwargs):
def resize_to_48(b64source):
if not b64source:
b64source = base64.b64encode(Binary().placeholder())
return image_resize_image(b64source, size=(48, 48))
return image_process(b64source, size=(48, 48))

values = {
'order': order,
@@ -36,7 +36,7 @@
import odoo.modules.registry
from odoo.api import call_kw, Environment
from odoo.modules import get_resource_path
from odoo.tools import limited_image_resize, topological_sort, html_escape, pycompat
from odoo.tools import image_process, topological_sort, html_escape, pycompat
from odoo.tools.mimetypes import guess_mimetype
from odoo.tools.translate import _
from odoo.tools.misc import str2bool, xlwt, file_open
@@ -1056,8 +1056,7 @@ def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas
if suffix in ('small', 'medium', 'large', 'big'):
image_base64 = getattr(odoo.tools, 'image_resize_image_%s' % suffix)(image_base64)

image_base64 = limited_image_resize(
image_base64, width=width, height=height, crop=crop)
image_base64 = image_process(image_base64, (width, height), crop=crop)

content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
@@ -164,7 +164,7 @@ def add_image_base64(self, res_model, res_id, image_base64, filename, disable_op
def _image_to_attachment(self, res_model, res_id, image_base64, name, datas_fname, disable_optimization=None):
Attachments = request.env['ir.attachment']
if not disable_optimization:
image_base64 = tools.image_optimize_for_web(image_base64)
image_base64 = tools.image_process(image_base64, verify_resolution=True)
attachment = Attachments.create({
'name': name,
'datas_fname': datas_fname,
@@ -96,7 +96,7 @@ def slugify(s):
logger.exception("Timeout: " + str(e))
continue

image_base64 = tools.image_optimize_for_web(image_base64)
image_base64 = tools.image_process(image_base64)
# append image extension in name
query += '.' + str.lower(tools.image_get_format(image_base64))

@@ -97,8 +97,7 @@ def get_user_profile_avatar(self, user_id, field='image_large', width=0, height=
if not image_base64:
image_base64 = self._get_default_avatar(field, headers, width, height)

image_base64 = tools.limited_image_resize(
image_base64, width=width, height=height, crop=crop)
image_base64 = tools.image_process(image_base64, (width, height), crop=crop)

content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
@@ -520,8 +520,7 @@ def slide_get_image(self, slide_id, field='image_medium', width=0, height=0, cro
if not image_base64:
image_base64 = self._get_default_avatar(field, headers, width, height)

image_base64 = tools.limited_image_resize(
image_base64, width=width, height=height, crop=crop)
image_base64 = tools.image_process(image_base64, (width, height), crop=crop)

content = base64.b64decode(image_base64)
headers.append(('Content-Length', len(content)))
@@ -120,7 +120,7 @@ def _inverse_country(self):
@api.depends('partner_id', 'partner_id.image')
def _compute_logo_web(self):
for company in self:
company.logo_web = tools.image_resize_image(company.partner_id.image, (180, None))
company.logo_web = tools.image_process(company.partner_id.image, (180, None))

@api.onchange('state_id')
def _onchange_state(self):
@@ -309,9 +309,9 @@ def _get_default_image(self, partner_type, is_company, parent_id):
with open(img_path, 'rb') as f:
image_base64 = base64.b64encode(f.read())
if image_base64 and colorize:
image_base64 = tools.image_colorize(image_base64)
image_base64 = tools.image_process(image_base64, colorize=True)

return tools.image_resize_image_big(image_base64)
return tools.image_process(image_base64, size=tools.IMAGE_BIG_SIZE)

@api.model
def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
Oops, something went wrong.

0 comments on commit c913e15

Please sign in to comment.
You can’t perform that action at this time.