Skip to content
Permalink
Browse files

[IMP] *: use new Image field

  • Loading branch information...
seb-odoo committed Apr 25, 2019
1 parent fa40968 commit 465987f2f273593465b1f4f650c8ecf1ae18c325
@@ -67,9 +67,9 @@ def _get_default_state(self):
horsepower_tax = fields.Float('Horsepower Taxation')
power = fields.Integer('Power', help='Power in kW of the vehicle')
co2 = fields.Float('CO2 Emissions', help='CO2 emissions of the vehicle')
image = fields.Binary(related='model_id.image', string="Logo", readonly=False)
image_medium = fields.Binary(related='model_id.image_medium', string="Logo (medium)", readonly=False)
image_small = fields.Binary(related='model_id.image_small', string="Logo (small)", readonly=False)
image = fields.Image(related='model_id.image', string="Logo", store=False)
image_medium = fields.Image(related='model_id.image_medium', string="Logo (medium)", store=False)
image_small = fields.Image(related='model_id.image_small', string="Logo (small)", store=False)
contract_renewal_due_soon = fields.Boolean(compute='_compute_contract_reminder', search='_search_contract_renewal_due_soon',
string='Has Contracts to renew', multi='contract_info')
contract_renewal_overdue = fields.Boolean(compute='_compute_contract_reminder', search='_search_get_overdue_contract_reminder',
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools
from odoo import api, fields, models


class FleetVehicleModel(models.Model):
@@ -12,9 +12,9 @@ class FleetVehicleModel(models.Model):
name = fields.Char('Model name', required=True)
brand_id = fields.Many2one('fleet.vehicle.model.brand', 'Make', required=True, help='Make of the vehicle')
vendors = fields.Many2many('res.partner', 'fleet_vehicle_model_vendors', 'model_id', 'partner_id', string='Vendors')
image = fields.Binary(related='brand_id.image', string="Logo", readonly=False)
image_medium = fields.Binary(related='brand_id.image_medium', string="Logo (medium)", readonly=False)
image_small = fields.Binary(related='brand_id.image_small', string="Logo (small)", readonly=False)
image = fields.Image(related='brand_id.image', string="Logo", store=False)
image_medium = fields.Image(related='brand_id.image_medium', string="Logo (medium)", store=False)
image_small = fields.Image(related='brand_id.image_small', string="Logo (small)", store=False)

@api.multi
@api.depends('name', 'brand_id')
@@ -41,24 +41,13 @@ class FleetVehicleModelBrand(models.Model):
_order = 'name asc'

name = fields.Char('Make', required=True)
image = fields.Binary("Logo",
image = fields.Image("Logo", size='big', avoid_if_small=True,
help="This field holds the image used as logo for the brand, limited to 1024x1024px.")
image_medium = fields.Binary("Medium-sized image",
image_medium = fields.Image("Medium-sized image", related='image', size='medium',
help="Medium-sized logo of the brand. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary("Small-sized image",
image_small = fields.Image("Small-sized image", related='image', size='small',
help="Small-sized logo of the brand. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
tools.image_resize_images(vals)
return super(FleetVehicleModelBrand, self).create(vals_list)

@api.multi
def write(self, vals):
tools.image_resize_images(vals)
return super(FleetVehicleModelBrand, self).write(vals)
@@ -4,7 +4,7 @@
import logging
from datetime import date

from odoo import api, tools, fields, models, _, exceptions
from odoo import api, fields, models, _, exceptions

_logger = logging.getLogger(__name__)

@@ -70,14 +70,14 @@ class GamificationBadge(models.Model):
name = fields.Char('Badge', required=True, translate=True)
active = fields.Boolean('Active', default=True)
description = fields.Text('Description', translate=True)
image = fields.Binary("Image", help="This field holds the image used for the badge.")
image_medium = fields.Binary(
"Medium-sized badge image",
image = fields.Image("Image", size='big', avoid_if_small=True, help="This field holds the image used for the badge.")
image_medium = fields.Image(
"Medium-sized badge image", related='image', size='medium',
help="Medium-sized image of the badge. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized badge image",
image_small = fields.Image(
"Small-sized badge image", related='image', size='small',
help="Small-sized image of the badge. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
@@ -137,17 +137,6 @@ class GamificationBadge(models.Model):
"Remaining Sending Allowed", compute='_remaining_sending_calc',
help="If a maximum is set")

@api.model_create_multi
def create(self, values_list):
for vals in values_list:
tools.image_resize_images(vals)
return super(GamificationBadge, self).create(values_list)

@api.multi
def write(self, vals):
tools.image_resize_images(vals)
return super(GamificationBadge, self).write(vals)

@api.depends('owner_ids')
def _get_owners_info(self):
"""Return:
@@ -3,7 +3,7 @@

from werkzeug.exceptions import Forbidden

from odoo import api, tools, fields, models
from odoo import api, fields, models
from odoo.tools.translate import html_translate


@@ -24,30 +24,27 @@ class KarmaRank(models.Model):
help="Motivational phrase to reach this rank")
karma_min = fields.Integer(string='Required Karma', help='Minimum karma needed to reach this rank')
user_ids = fields.One2many('res.users', 'rank_id', string='Users', help="Users having this rank")
image = fields.Binary('Rank Icon')
image_medium = fields.Binary(
"Medium-sized rank icon",
image = fields.Image('Rank Icon', size='big', avoid_if_small=True)
image_medium = fields.Image(
"Medium-sized rank icon", related='image', size='medium',
help="Medium-sized icon of the rank. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized rank icon",
image_small = fields.Image(
"Small-sized rank icon", related='image', size='small',
help="Small-sized icon of the rank. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")

@api.model_create_multi
def create(self, values_list):
for vals in values_list:
tools.image_resize_images(vals)
res = super(KarmaRank, self).create(values_list)
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users._recompute_rank()
return res

@api.multi
def write(self, vals):
tools.image_resize_images(vals)
res = super(KarmaRank, self).write(vals)
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users._recompute_rank()
@@ -170,16 +170,16 @@ def _default_image(self):
job_title = fields.Char("Job Title")

# image: all image fields are base64 encoded and PIL-supported
image = fields.Binary(
"Photo", default=_default_image,
image = fields.Image(
"Photo", default=_default_image, size='big', avoid_if_small=True,
help="This field holds the image used as photo for the employee, limited to 1024x1024px.")
image_medium = fields.Binary(
"Medium-sized photo",
image_medium = fields.Image(
"Medium-sized photo", related='image', size='medium',
help="Medium-sized photo of the employee. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized photo",
image_small = fields.Image(
"Small-sized photo", related='image', size='small',
help="Small-sized photo of the employee. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
@@ -274,7 +274,6 @@ def _sync_user(self, user):
def create(self, vals):
if vals.get('user_id'):
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id'])))
tools.image_resize_images(vals)
employee = super(Employee, self).create(vals)
url = '/web#%s' % url_encode({'action': 'hr.plan_wizard_action', 'active_id': employee.id, 'active_model': 'hr.employee'})
employee._message_log(_('<b>Congratulations !</b> May I recommand you to setup an <a href="%s">onboarding plan ?</a>') % (url))
@@ -292,7 +291,6 @@ def write(self, vals):
self.env['res.partner.bank'].browse(account_id).partner_id = vals['address_home_id']
if vals.get('user_id'):
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id'])))
tools.image_resize_images(vals)
res = super(Employee, self).write(vals)
if vals.get('department_id') or vals.get('user_id'):
department_id = vals['department_id'] if vals.get('department_id') else self[:1].department_id.id
@@ -43,13 +43,13 @@ def _default_user_ids(self):
nbr_channel = fields.Integer('Number of conversation', compute='_compute_nbr_channel', store=False, readonly=True)

# images fields
image = fields.Binary('Image', default=_default_image,
image = fields.Image('Image', default=_default_image, size='big', avoid_if_small=True,
help="This field holds the image used as photo for the group, limited to 1024x1024px.")
image_medium = fields.Binary('Medium',
image_medium = fields.Image('Medium', related='image', size='medium',
help="Medium-sized photo of the group. It is automatically "\
"resized as a 128x128px image, with aspect ratio preserved. "\
"Use this field in form views or some kanban views.")
image_small = fields.Binary('Thumbnail',
image_small = fields.Image('Thumbnail', related='image', size='small',
help="Small-sized photo of the group. It is automatically "\
"resized as a 64x64px image, with aspect ratio preserved. "\
"Use this field anywhere a small image is required.")
@@ -86,16 +86,6 @@ def _compute_nbr_channel(self):
for record in self:
record.nbr_channel = len(record.channel_ids)

@api.model
def create(self, vals):
tools.image_resize_images(vals)
return super(ImLivechatChannel, self).create(vals)

@api.multi
def write(self, vals):
tools.image_resize_images(vals)
return super(ImLivechatChannel, self).write(vals)

# --------------------------
# Action Methods
# --------------------------
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools
from odoo import api, fields, models

from odoo.addons import decimal_precision as dp
from odoo.tools import formatLang
@@ -92,29 +92,19 @@ class LunchProduct(models.Model):
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')

# image: all image fields are base64 encoded and PIL-supported
image = fields.Binary(
"Image",
image = fields.Image(
"Image", size='big', avoid_if_small=True,
help="This field holds the image used as image for the product, limited to 1024x1024px.")
image_medium = fields.Binary(
"Medium-sized image",
image_medium = fields.Image(
"Medium-sized image", related='image', size='medium',
help="Medium-sized image of the product. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved, "
"only when the image exceeds one of those sizes. Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized image",
image_small = fields.Image(
"Small-sized image", related='image', size='small',
help="Small-sized image of the product. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")

new_until = fields.Date('New Until')
favorite_user_ids = fields.Many2many('res.users', 'lunch_product_favorite_user_rel', 'product_id', 'user_id')

@api.model_create_multi
def create(self, vals_list):
for values in vals_list:
tools.image_resize_images(values)
return super(LunchProduct, self).create(vals_list)

def write(self, values):
tools.image_resize_images(values)
return super(LunchProduct, self).write(values)
@@ -102,13 +102,13 @@ def default_get(self, fields):
"Note that they will be able to manage their subscription manually "
"if necessary.")
# image: all image fields are base64 encoded and PIL-supported
image = fields.Binary("Photo", default=_get_default_image,
image = fields.Image("Photo", default=_get_default_image, size='big', avoid_if_small=True,
help="This field holds the image used as photo for the group, limited to 1024x1024px.")
image_medium = fields.Binary('Medium-sized photo',
image_medium = fields.Image('Medium-sized photo', related='image', size='medium',
help="Medium-sized photo of the group. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary('Small-sized photo',
image_small = fields.Image('Small-sized photo', related='image', size='small',
help="Small-sized photo of the group. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
@@ -219,7 +219,6 @@ def create(self, vals):
defaults = self.default_get(['image'])
vals['image'] = defaults['image']

tools.image_resize_images(vals)
# Create channel and alias
channel = super(Channel, self.with_context(
alias_model_name=self._name, alias_parent_model_name=self._name, mail_create_nolog=True, mail_create_nosubscribe=True)
@@ -258,7 +257,6 @@ def write(self, vals):
if not self.env.user.has_group('base.group_system'):
raise UserError("You do not possess the rights to modify fields related to moderation on one of the channels you are modifying.")

tools.image_resize_images(vals)
result = super(Channel, self).write(vals)

if vals.get('group_ids'):
@@ -76,7 +76,7 @@ def _get_default_author(self):
'res.partner', 'Author', index=True,
ondelete='set null', default=_get_default_author,
help="Author of the message. If not set, email_from may hold an email address that did not match any partner.")
author_avatar = fields.Binary("Author's avatar", related='author_id.image_small', readonly=False)
author_avatar = fields.Image("Author's avatar", related='author_id.image_small', store=False)
# recipients: include inactive partners (they may have been archived after
# the message was sent, but they should remain visible in the relation)
partner_ids = fields.Many2many('res.partner', string='Recipients',
@@ -8,7 +8,7 @@
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.tools import consteq, float_round, image_resize_image, ustr
from odoo.addons.base.models import ir_module
from odoo.exceptions import ValidationError
from odoo import api, SUPERUSER_ID
@@ -150,15 +150,15 @@ def _get_default_view_template_id(self):
module_id = fields.Many2one('ir.module.module', string='Corresponding Module')
module_state = fields.Selection(selection=ir_module.STATES, string='Installation State', related='module_id.state', readonly=False)

image = fields.Binary(
"Image", help="This field holds the image used for this provider, limited to 1024x1024px")
image_medium = fields.Binary(
"Medium-sized image",
image = fields.Image(
"Image", size='big', avoid_if_small=True, help="This field holds the image used for this provider, limited to 1024x1024px")
image_medium = fields.Image(
"Medium-sized image", related='image', size='medium',
help="Medium-sized image of this provider. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized image",
image_small = fields.Image(
"Small-sized image", related='image', size='small',
help="Small-sized image of this provider. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
@@ -275,16 +275,6 @@ def _create_missing_journal_for_acquirers(self, company=None):
journals += acquirer.journal_id
return journals

@api.model
def create(self, vals):
image_resize_images(vals)
return super(PaymentAcquirer, self).create(vals)

@api.multi
def write(self, vals):
image_resize_images(vals)
return super(PaymentAcquirer, self).write(vals)

@api.multi
def toggle_website_published(self):
''' When clicking on the website publish toggle button, the website_published is reversed and
@@ -501,28 +491,12 @@ class PaymentIcon(models.Model):

name = fields.Char(string='Name')
acquirer_ids = fields.Many2many('payment.acquirer', string="Acquirers", help="List of Acquirers supporting this payment icon.")
image = fields.Binary(
"Image", help="This field holds the image used for this payment icon, limited to 1024x1024px")

image_payment_form = fields.Binary(
"Image displayed on the payment form", attachment=True)
image = fields.Image(
"Image", size='small', help="This field holds the image used for this payment icon, limited to 64x64px")

@api.model_create_multi
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))
return super(PaymentIcon, self).create(vals_list)
image_payment_form = fields.Image(
"Image displayed on the payment form", related='image', width=45, height=30)

@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))
return super(PaymentIcon, self).write(vals)

class PaymentTransaction(models.Model):
""" Transaction Model. Each specific acquirer can extend the model by adding
Oops, something went wrong.

0 comments on commit 465987f

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