def _set_image(self): if self.image_small: self.image = tools.image_resize_image_small( self.image_small, size=(102, 50) ) elif self.image_medium: self.image = tools.image_resize_image_small( self.image_medium, size=(102, 50) )
def _get_default_image(self): colorize, image_path, image = False, False, False # if partner_type in ['other'] and parent_id: # parent_image = self.browse(parent_id).image # image = parent_image and parent_image.decode('base64') or None if self.module_id == 'amazon_odoo_v11': image_path = get_module_resource('base_ecommerce_v11', 'static/images', 'amazon_logo.png') if self.module_id == 'ebay_odoo_v11': image_path = get_module_resource('base_ecommerce_v11', 'static/images', 'EBay_logo.png') if self.module_id == 'magento_odoo_v10': image_path = get_module_resource('base_ecommerce_v11', 'static/images', 'logomagento.png') if self.module_id == 'shopify_odoo_v10': image_path = get_module_resource('base_ecommerce_v11', 'static/images', 'shopify.png') # if image_path: # with open(image_path, 'rb') as f: # image = f.read() # if image_path: # f = open(image_path, 'rb') # image = f.read() # image=Image.open(image_path) # if image and colorize: # image = tools.image_colorize(image) # self.image = tools.image_resize_image_big(image.encode('base64')) # self.image = base64.b64encode(image).decode('ascii') self.image=tools.image_resize_image_small(base64.b64encode(open(image_path, 'rb').read()))
def _compute_images(self): for record in self: record.image_medium = tools.image_resize_image_medium( record.image, ) record.image_small = tools.image_resize_image_small( record.image, )
def _compute_images(self): for rec in self: rec.image_medium = tools.image_resize_image_medium( rec.image, avoid_if_small=True) rec.image_small = tools.image_resize_image_small(rec.image)
def _compute_images(self): for rec in self: rec.image_medium = tools.image_resize_image_medium(rec.image) rec.image_small = tools.image_resize_image_small(rec.image)
def _get_small_image(self): for record in self: record["image_small"] = tools.image_resize_image_small( record.image)
def _default_image_small(self): if not self.image: return False return tools.image_resize_image_small(self.image)
def _change_template_image(self, to_type, to_img_bg=None, in_cache=False): """ Change template image to specified to_type's image or to_img_bg. Args: to_type (str): Value specified allowed from image_type field which the image should be targeted to. Accepted values are: GLOBAL * product_image field defined in res.company CATEGORY * product's categ_id field's image NONE * Deletes the image CUSTOM * Set to the image you specify using to_img_bg. Note that targeting to custom will prevent the image from automatically being changed in the future until deleted or manually re-mapped to a default image. to_img_bg (base64): Can be used as an override if the template images should be changed to a specific image. Image is resized to image big value and scaled down to medium and small values. Note that to_type is required even if to_img_bg arg is supplied. in_cache (bool): Set True if calling this method to change the images in cache (helpful when calling from an onchange method in product.template) Returns: ProductTemplate: Recordset if tmpl images have been changed. None: if any of the conditions below are True. """ if to_type not in (NONE, GLOBAL, CATEGORY, CUSTOM): raise ValueError( 'to_type value must be either NONE, GLOBAL, CATEGORY, ' 'or CUSTOM. It is currently %s' % to_type) if to_type == CUSTOM and not to_img_bg: raise ValueError( 'to_img_bg arg must be provided if to_type is CUSTOM') if to_type == NONE and to_img_bg: raise ValueError('to_img_bg should be None if to_type is NONE') write_map = defaultdict(lambda: self.env['product.template'].browse()) if to_img_bg: to_img_bg = tools.image_resize_image_big(to_img_bg) write_map[to_img_bg] += self elif to_type == NONE: write_map[None] += self elif to_type == GLOBAL: for record in self: write_map[record.company_id.product_image] += record elif to_type == CATEGORY: for record in self: write_map[record.categ_id.image] += record if in_cache: for img_bg, records in write_map.iteritems(): img_md = tools.image_resize_image_medium(img_bg) img_sm = tools.image_resize_image_small(img_bg) for record in records: record.image = img_bg record.image_medium = img_md record.image_small = img_sm record.image_type = to_type else: for img_bg, records in write_map.iteritems(): # image only written to last or last few records # if writing directly on recordset for record in records: record.write({ 'image': img_bg, 'image_type': to_type, }) return self
def _get_small_image(self): for record in self: record["image_small"] = tools.image_resize_image_small(record.image)
def _compute_image(self): for r in self: r.image_small = tools.image_resize_image_small(r.image)