website.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # -*- coding: utf-8 -*-
  2. # Part of Biztech Consultancy. See LICENSE file for full copyright and licensing details.
  3. import math
  4. import werkzeug
  5. from openerp import api, fields, models, _
  6. from openerp.http import request
  7. from openerp.addons.website_sale.controllers import main
  8. class WebsiteMenu(models.Model):
  9. _inherit = "website.menu"
  10. is_megamenu = fields.Boolean(string='Is megamenu...?')
  11. megamenu_type = fields.Selection([('2_col', '2 Columns'),
  12. ('3_col', '3 Columns'),
  13. ('4_col', '4 Columns')],
  14. default='3_col',
  15. string="Megamenu type")
  16. megamenu_bg = fields.Boolean(string='Want to set megamenu background', default=False)
  17. megamenu_bg_img_color = fields.Selection([('bg_img', 'Background image'),
  18. ('bg_color', 'Background color')],
  19. default='bg_img',
  20. string="Megamenu background selection")
  21. megamenu_bg_image = fields.Binary(string="Background image for megamenu")
  22. megamenu_bg_color = fields.Char(string="Background color for megamenu",
  23. default='#ccc',
  24. help="Background color for megamenu, for setting background color you have to pass hexacode here.")
  25. category_slider = fields.Boolean(string='Want to display category slider', default=False)
  26. carousel_header_name = fields.Char(string="Slider label",
  27. default="Latest", translate=True,
  28. help="Header name for carousel slider in megamenu")
  29. category_slider_position = fields.Selection([('left', 'Left'), ('right', 'Right')],
  30. default='left', string="Category Slider Position")
  31. menu_icon = fields.Boolean(string='Want to display menu icon', default=False)
  32. menu_icon_image = fields.Binary(string="Menu Icon", help="Menu icon for your menu")
  33. display_menu_footer = fields.Boolean(string="Display menu footer", default=False,
  34. help="For displaying footer in megamenu")
  35. menu_footer = fields.Html(string="Footer content",
  36. help="Footer name for megamenu")
  37. customize_menu_colors = fields.Boolean(string='Want to customize menu colors', default=False)
  38. main_category_color = fields.Char(string='Main category color',
  39. help="Set color for main category in megamenu")
  40. sub_category_color = fields.Char(string='Sub category color',
  41. help="Set color for sab category in megamenu")
  42. class website(models.Model):
  43. _inherit = 'website'
  44. # For Multi image
  45. thumbnail_panel_position = fields.Selection([
  46. ('left', 'Left'),
  47. ('right', 'Right'),
  48. ('bottom', 'Bottom'),
  49. ], default='left',
  50. string='Thumbnails panel position',
  51. help="Select the position where you want to display the thumbnail panel in multi image.")
  52. interval_play = fields.Char(string='Play interval of slideshow', default='5000',
  53. help='With this field you can set the interval play time between two images.')
  54. enable_disable_text = fields.Boolean(string='Enable the text panel',
  55. default=True,
  56. help='Enable/Disable text which is visible on the image in multi image.')
  57. color_opt_thumbnail = fields.Selection([
  58. ('default', 'Default'),
  59. ('b_n_w', 'B/W'),
  60. ('sepia', 'Sepia'),
  61. ('blur', 'Blur'), ],
  62. default='default',
  63. string="Thumbnail overlay effects")
  64. no_extra_options = fields.Boolean(string='Slider effects',
  65. default=True,
  66. help="Slider with all options for next, previous, play, pause, fullscreen, hide/show thumbnail panel.")
  67. change_thumbnail_size = fields.Boolean(string="Change thumbnail size", default=False)
  68. thumb_height = fields.Char(string='Thumb height', default=50)
  69. thumb_width = fields.Char(string='Thumb width', default=88)
  70. # For Sort By
  71. enable_sort_by = fields.Boolean(string='Enable product sorting option',
  72. help='For enabling product sorting feature in website.',
  73. default=True)
  74. # For first last pager
  75. enable_first_last_pager = fields.Boolean(string="Enable First and Last Pager", default=True,
  76. help="Enable this checkbox to make 'First' and 'Last' button in pager on website.")
  77. # Product per grid
  78. product_display_grid = fields.Selection([('2', '2'), ('3', '3'), ('4', '4')],
  79. default='3', string='Product per grid', help="Display no. of products per line in website product grid.")
  80. # For first last pager
  81. def get_pager_selection(self):
  82. prod_per_page = self.env['product.per.page'].search([])
  83. prod_per_page_no = self.env['product.per.page.no'].search([])
  84. values = {
  85. 'name': prod_per_page.name,
  86. 'page_no': prod_per_page_no,
  87. }
  88. return values
  89. def get_current_pager_selection(self):
  90. if request.session.get('default_paging_no'):
  91. return int(request.session.get('default_paging_no'))
  92. else:
  93. return main.PPG
  94. def pager(self, cr, uid, ids, url, total, page=1, step=30, scope=5, url_args=None, context=None):
  95. res = super(website, self). pager(cr, uid, ids, url=url,
  96. total=total,
  97. page=page,
  98. step=step,
  99. scope=scope,
  100. url_args=url_args,
  101. context=context)
  102. # Compute Pager
  103. page_count = int(math.ceil(float(total) / step))
  104. page = max(1, min(int(page if str(page).isdigit() else 1), page_count))
  105. scope -= 1
  106. pmin = max(page - int(math.floor(scope/2)), 1)
  107. pmax = min(pmin + scope, page_count)
  108. if pmax - pmin < scope:
  109. pmin = pmax - scope if pmax - scope > 0 else 1
  110. def get_url(page):
  111. _url = "%s/page/%s" % (url, page) if page > 1 else url
  112. if url_args and not url_args.get('tag') and not url_args.get('range1') and not url_args.get('range2') and not url_args.get('max1') and not url_args.get('min1') and not url_args.get('sort_id'):
  113. _url = "%s?%s" % (_url, werkzeug.url_encode(url_args))
  114. return _url
  115. res.update({
  116. # Overrite existing
  117. "page_start": {
  118. 'url': get_url(pmin),
  119. 'num': pmin
  120. },
  121. "page_previous": {
  122. 'url': get_url(max(pmin, page - 1)),
  123. 'num': max(pmin, page - 1)
  124. },
  125. "page_next": {
  126. 'url': get_url(min(pmax, page + 1)),
  127. 'num': min(pmax, page + 1)
  128. },
  129. "page_end": {
  130. 'url': get_url(pmax),
  131. 'num': pmax
  132. },
  133. 'page_first': {
  134. 'url': get_url(1),
  135. 'num': 1
  136. },
  137. 'page_last': {
  138. 'url': get_url(int(res['page_count'])),
  139. 'num': int(res['page_count'])
  140. },
  141. 'pages': [
  142. {'url': get_url(page), 'num': page}
  143. for page in xrange(pmin, pmax+1)
  144. ]
  145. })
  146. return res
  147. # For multi image
  148. @api.multi
  149. def get_multiple_images(self, product_id=None):
  150. product_img_data = False
  151. if product_id:
  152. self.env.cr.execute(
  153. "select id from biztech_product_images where product_tmpl_id=%s and more_view_exclude IS NOT TRUE order by sequence", ([product_id]))
  154. product_ids = map(lambda x: x[0], self.env.cr.fetchall())
  155. if product_ids:
  156. product_img_data = self.env['biztech.product.images'].browse(
  157. product_ids)
  158. return product_img_data
  159. # For brands
  160. def sale_product_domain(self, cr, uid, ids, context=None):
  161. domain = super(website, self).sale_product_domain(cr, uid, ids=ids,
  162. context=context)
  163. if 'brand_id' in request.context:
  164. domain.append(
  165. ('product_brand_id', '=', request.context['brand_id']))
  166. return domain
  167. # For product tags feature
  168. def get_product_tags(self):
  169. product_tags = self.env['biztech.product.tags'].search([])
  170. return product_tags
  171. # For Sorting products
  172. def get_sort_by_data(self):
  173. request.session['product_sort_name'] = ''
  174. sort_by = self.env['biztech.product.sortby'].search([])
  175. return sort_by
  176. # For setting current sort list
  177. def set_current_sorting_data(self):
  178. sort_name = request.session.get('product_sort_name')
  179. return sort_name
  180. # For megamenu
  181. @api.multi
  182. def get_public_product_category(self, submenu):
  183. categories = self.env['product.public.category'].search([('parent_id', '=', False),
  184. ('include_in_megamenu',
  185. '!=', False),
  186. ('menu_id', '=', submenu.id)],
  187. order="sequence")
  188. return categories
  189. def get_public_product_child_category(self, children):
  190. child_categories = []
  191. for child in children:
  192. categories = self.env['product.public.category'].search([
  193. ('id', '=', child.id),
  194. ('include_in_megamenu', '!=', False)], order="sequence")
  195. if categories:
  196. child_categories.append(categories)
  197. return child_categories
  198. class WebsiteConfigSettings(models.TransientModel):
  199. _inherit = 'website.config.settings'
  200. # For multi image
  201. thumbnail_panel_position = fields.Selection([
  202. ('left', 'Left'),
  203. ('right', 'Right'),
  204. ('bottom', 'Bottom')],
  205. string='Thumbnails panel position',
  206. related='website_id.thumbnail_panel_position',
  207. help="Select the position where you want to display the thumbnail panel in multi image.")
  208. interval_play = fields.Char(string='Play interval of slideshow',
  209. related='website_id.interval_play',
  210. help='With this field you can set the interval play time between two images.')
  211. enable_disable_text = fields.Boolean(string='Enable the text panel',
  212. related='website_id.enable_disable_text',
  213. help='Enable/Disable text which is visible on the image in multi image.')
  214. color_opt_thumbnail = fields.Selection([
  215. ('default', 'Default'),
  216. ('b_n_w', 'B/W'),
  217. ('sepia', 'Sepia'),
  218. ('blur', 'Blur')],
  219. related='website_id.color_opt_thumbnail',
  220. string="Thumbnail overlay effects")
  221. no_extra_options = fields.Boolean(string='Slider effects',
  222. # default=True,
  223. related='website_id.no_extra_options',
  224. help="Slider with all options for next, previous, play, pause, fullscreen, hide/show thumbnail panel.")
  225. change_thumbnail_size = fields.Boolean(string="Change thumbnail size",
  226. related="website_id.change_thumbnail_size"
  227. )
  228. thumb_height = fields.Char(string='Thumb height',
  229. related="website_id.thumb_height"
  230. )
  231. thumb_width = fields.Char(string='Thumb width',
  232. related="website_id.thumb_width"
  233. )
  234. # For Sort By
  235. enable_sort_by = fields.Boolean(related="website_id.enable_sort_by", string='Enable product sorting option',
  236. help='For enabling product sorting feature in website.',
  237. default=True)
  238. # For first last pager
  239. enable_first_last_pager = fields.Boolean(related='website_id.enable_first_last_pager',
  240. string="Enable First and Last Pager", default=True,
  241. help="Enable this checkbox to make 'First' and 'Last' button in pager on website.")
  242. # Product per grid
  243. product_display_grid = fields.Selection(related='website_id.product_display_grid',
  244. default='3', string='Product per grid', help="Display no. of products per line in website product grid.")