def write(self, vals): if 'design_image' in vals.keys() and vals['design_image']: vals.update({ 'design_image_small': tools.image_resize_image_medium( vals['design_image'].encode('ascii')) }) if self.product_id.product_type in [ 'product' ] and not self.sales_order_id.image: self.sales_order_id.image = vals['design_image'] if 'design_image_2' in vals.keys() and vals['design_image_2']: vals.update({ 'design_image_2_small': tools.image_resize_image_medium( vals['design_image_2'].encode('ascii')) }) if 'design_image_3' in vals.keys() and vals['design_image_3']: vals.update({ 'design_image_3_small': tools.image_resize_image_medium( vals['design_image_3'].encode('ascii')) }) initial_qty = self.qty initial_product_id = self.product_id initial_price = self.price initial_fabric_color = self.fabric_color test = self.env['sales__order.price_line'].browse( self.price_line_id.id) for t in test: t.qty = vals['qty'] if 'qty' in vals.keys() else self.qty if 'product_id' in vals.keys(): product = self.env['famotain.product'].browse( vals['product_id'])[0] t.amount = product.price t.debit = t.qty * product.price t.description = product.name product_order = super(ProductOrder, self).write(vals) if any(c in vals.keys() for c in ('qty', 'product_id')): msg = "{}pcs {} Rp. {:,} product order changed to {}pcs {} Rp. {:,}".format( initial_qty, initial_product_id.display_name, initial_price, self.qty, self.product_id.display_name, self.price) self.sales_order_id.message_post(body=msg) if 'fabric_color' in vals.keys(): msg = "{} description {} changed to {}".format( initial_product_id.display_name, initial_fabric_color, self.fabric_color) self.sales_order_id.message_post(body=msg) return product_order
def create(self, vals): if vals.get('image'): vals['file_size'] = len(vals.get('image')) * 0.75 vals['image_medium'] = tools.image_resize_image_medium(vals.get('image'), avoid_if_small=True) else: vals['file_size'] = 0 vals['image_medium'] = False return super(Image, self).create(vals)
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 create(self, vals): image = False if 'design_image' in vals.keys() and vals['design_image']: vals.update({ 'design_image_small': tools.image_resize_image_medium( vals['design_image'].encode('ascii')) }) image = True if 'design_image_2' in vals.keys() and vals['design_image_2']: vals.update({ 'design_image_2_small': tools.image_resize_image_medium( vals['design_image_2'].encode('ascii')) }) if 'design_image_3' in vals.keys() and vals['design_image_3']: vals.update({ 'design_image_3_small': tools.image_resize_image_medium( vals['design_image_3'].encode('ascii')) }) product_order = super(ProductOrder, self).create(vals) product_order.deadline = product_order.sales_order_id.deadline # product_order.name = """{}/{}""".format(product_order.qty, product_order.product_id.code) price_line = product_order.create_price_line() product_order.price_line_id = price_line.id # create product order kalo sales order udh confirm/approve berarti product order state juga sama if product_order.sales_order_id.state in ['confirm', 'approve']: product_order.state = 'confirm' if product_order.sales_order_id.state in ['approve']: product_order.action_approve() if image and product_order.product_id.product_type in [ 'product' ] and not product_order.sales_order_id.image: product_order.sales_order_id.image = vals['design_image'] msg = "{}pcs {} Rp. {:,} product order created".format( product_order.qty, product_order.product_id.display_name, product_order.price) product_order.sales_order_id.message_post(body=msg) return product_order
def _get_default_image(self): colorize, img_path, image = False, False, False if not image: img_path = get_module_resource('wolftrakglobal', 'static/src/img', 'gps.png') colorize = True if img_path: with open(img_path, 'rb') as f: image = f.read() if image and colorize: image = tools.image_colorize(image) return tools.image_resize_image_medium(image.encode('base64'))
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 _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 _compute_image_medium(self): for record in self: record.image_medium = tools.image_resize_image_medium(record.image)
def write(self, values): if 'image' in values: values['image'] = tools.image_resize_image_medium(values['image']) return super(ExtendedLead, self).write(values)
def _reduce_customer_picture(self): for rec in self: rec.picture = tools.image_resize_image_medium(rec.picture)
def _compute_image_medium(self): self.image_medium = tools.image_resize_image_medium(self.image)