product.py 2.2 KB

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