product.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. See LICENSE file for full copyright and licensing details.
  3. from openerp import api, fields, models
  4. class product_images(models.Model):
  5. _name = 'product.images'
  6. _description = "Add Multiple Image in Product"
  7. name = fields.Char(string='Label')
  8. image = fields.Binary(string='Image')
  9. sequence = fields.Integer(string='Sort Order')
  10. product_tmpl_id = fields.Many2one('product.template', string='Product')
  11. more_view_exclude = fields.Boolean(string="More View Exclude")
  12. class product_template(models.Model):
  13. _inherit = 'product.template'
  14. _description = "Multiple Images"
  15. images = fields.One2many('product.images', 'product_tmpl_id',
  16. string='Images')
  17. multi_image = fields.Boolean("Add Multiple Images?")
  18. class website(models.Model):
  19. _inherit = 'website'
  20. def get_multiple_images(self, product_id=None):
  21. product_img_data = False
  22. if product_id:
  23. self._cr.execute(
  24. 'select id from product_images where product_tmpl_id=%s and more_view_exclude IS NOT TRUE order by sequence', ([product_id]))
  25. product_ids = map(lambda x: x[0], self._cr.fetchall())
  26. if product_ids:
  27. product_img_data = self.env[
  28. 'product.images'].browse(product_ids)
  29. return product_img_data
  30. def get_zoom_feature(self):
  31. zoom = self.env['product.multiple.image.config'].search(
  32. [('is_zoom_feature', '=', True)])
  33. if zoom:
  34. return True
  35. else:
  36. return False
  37. def get_image_url(self, record, field, size=None):
  38. """Returns a local url that points to the image field of a given browse record."""
  39. model = record._name
  40. sudo_record = record.sudo()
  41. id = '%s_%s' % (record.id, hashlib.sha1(
  42. sudo_record.write_date or sudo_record.create_date or '').hexdigest()[0:7])
  43. size = '' if size is None else '/%s' % size
  44. return '/website/image/%s/%s/%s%s' % (model, id, field, size)