website.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. 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. PPG = 18
  9. class WebsiteMenu(models.Model):
  10. _inherit = "website.menu"
  11. is_megamenu = fields.Boolean(string='Is megamenu...?')
  12. megamenu_type = fields.Selection([('2_col', '2 Columns'),
  13. ('3_col', '3 Columns'),
  14. ('4_col', '4 Columns')],
  15. default='3_col',
  16. string="Megamenu type")
  17. megamenu_bg = fields.Boolean(string='Want to set megamenu background', default=False)
  18. megamenu_bg_img_color = fields.Selection([('bg_img', 'Background image'),
  19. ('bg_color', 'Background color')],
  20. default='bg_img',
  21. string="Megamenu background selection")
  22. megamenu_bg_image = fields.Binary(string="Background image for megamenu")
  23. megamenu_bg_color = fields.Char(string="Background color for megamenu",
  24. default='#ccc',
  25. help="Background color for megamenu, for setting background color you have to pass hexacode here.")
  26. category_slider = fields.Boolean(string='Want to display category slider', default=False)
  27. carousel_header_name = fields.Char(string="Slider label",
  28. default="Latest", translate=True,
  29. help="Header name for carousel slider in megamenu")
  30. category_slider_position = fields.Selection([('left', 'Left'), ('right', 'Right')],
  31. default='left', string="Category Slider Position")
  32. menu_icon = fields.Boolean(string='Want to display menu icon', default=False)
  33. menu_icon_image = fields.Binary(string="Menu Icon", help="Menu icon for your menu")
  34. display_menu_footer = fields.Boolean(string="Display menu footer", default=False,
  35. help="For displaying footer in megamenu")
  36. menu_footer = fields.Html(string="Footer content",
  37. help="Footer name for megamenu")
  38. customize_menu_colors = fields.Boolean(string='Want to customize menu colors', default=False)
  39. main_category_color = fields.Char(string='Main category color',
  40. help="Set color for main category in megamenu")
  41. sub_category_color = fields.Char(string='Sub category color',
  42. help="Set color for sab category in megamenu")
  43. class website(models.Model):
  44. _inherit = 'website'
  45. # For Multi image
  46. thumbnail_panel_position = fields.Selection([
  47. ('left', 'Left'),
  48. ('right', 'Right'),
  49. ('bottom', 'Bottom'),
  50. ], default='left',
  51. string='Thumbnails panel position',
  52. help="Select the position where you want to display the thumbnail panel in multi image.")
  53. interval_play = fields.Char(string='Play interval of slideshow', default='5000',
  54. help='With this field you can set the interval play time between two images.')
  55. enable_disable_text = fields.Boolean(string='Enable the text panel',
  56. default=True,
  57. help='Enable/Disable text which is visible on the image in multi image.')
  58. color_opt_thumbnail = fields.Selection([
  59. ('default', 'Default'),
  60. ('b_n_w', 'B/W'),
  61. ('sepia', 'Sepia'),
  62. ('blur', 'Blur'), ],
  63. default='default',
  64. string="Thumbnail overlay effects")
  65. no_extra_options = fields.Boolean(string='Slider effects',
  66. default=True,
  67. help="Slider with all options for next, previous, play, pause, fullscreen, hide/show thumbnail panel.")
  68. change_thumbnail_size = fields.Boolean(string="Change thumbnail size", default=False)
  69. thumb_height = fields.Char(string='Thumb height', default=50)
  70. thumb_width = fields.Char(string='Thumb width', default=88)
  71. # For Sort By
  72. enable_sort_by = fields.Boolean(string='Enable product sorting option',
  73. help='For enabling product sorting feature in website.',
  74. default=True)
  75. # For first last pager
  76. enable_first_last_pager = fields.Boolean(string="Enable First and Last Pager", default=True,
  77. help="Enable this checkbox to make 'First' and 'Last' button in pager on website.")
  78. # Product per grid
  79. product_display_grid = fields.Selection([('2', '2'), ('3', '3'), ('4', '4')],
  80. default='3', string='Product per grid', help="Display no. of products per line in website product grid.")
  81. # For first last pager
  82. def get_pager_selection(self):
  83. prod_per_page = self.env['product.per.page'].search([])
  84. prod_per_page_no = self.env['product.per.page.no'].search([])
  85. values = {
  86. 'name': prod_per_page.name,
  87. 'page_no': prod_per_page_no,
  88. }
  89. return values
  90. def get_current_pager_selection(self):
  91. if request.session.get('default_paging_no'):
  92. return int(request.session.get('default_paging_no'))
  93. else:
  94. return PPG
  95. @api.model
  96. def pager(self, url, total, page=1, step=30, scope=5, url_args=None):
  97. res = super(website, self). pager(url=url,
  98. total=total,
  99. page=page,
  100. step=step,
  101. scope=scope,
  102. url_args=url_args)
  103. # Compute Pager
  104. page_count = int(math.ceil(float(total) / step))
  105. page = max(1, min(int(page if str(page).isdigit() else 1), page_count))
  106. scope -= 1
  107. pmin = max(page - int(math.floor(scope/2)), 1)
  108. pmax = min(pmin + scope, page_count)
  109. if pmax - pmin < scope:
  110. pmin = pmax - scope if pmax - scope > 0 else 1
  111. def get_url(page):
  112. _url = "%s/page/%s" % (url, page) if page > 1 else url
  113. 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'):
  114. _url = "%s?%s" % (_url, werkzeug.url_encode(url_args))
  115. return _url
  116. res.update({
  117. # Overrite existing
  118. "page_start": {
  119. 'url': get_url(pmin),
  120. 'num': pmin
  121. },
  122. "page_previous": {
  123. 'url': get_url(max(pmin, page - 1)),
  124. 'num': max(pmin, page - 1)
  125. },
  126. "page_next": {
  127. 'url': get_url(min(pmax, page + 1)),
  128. 'num': min(pmax, page + 1)
  129. },
  130. "page_end": {
  131. 'url': get_url(pmax),
  132. 'num': pmax
  133. },
  134. 'page_first': {
  135. 'url': get_url(1),
  136. 'num': 1
  137. },
  138. 'page_last': {
  139. 'url': get_url(int(res['page_count'])),
  140. 'num': int(res['page_count'])
  141. },
  142. 'pages': [
  143. {'url': get_url(page), 'num': page}
  144. for page in xrange(pmin, pmax+1)
  145. ]
  146. })
  147. return res
  148. # For multi image
  149. @api.multi
  150. def get_multiple_images(self, product_id=None):
  151. product_img_data = False
  152. if product_id:
  153. self.env.cr.execute(
  154. "select id from biztech_product_images where product_tmpl_id=%s and more_view_exclude IS NOT TRUE order by sequence", ([product_id]))
  155. product_ids = map(lambda x: x[0], self.env.cr.fetchall())
  156. if product_ids:
  157. product_img_data = self.env['biztech.product.images'].browse(
  158. product_ids)
  159. return product_img_data
  160. # For brands
  161. def sale_product_domain(self):
  162. domain = super(website, self).sale_product_domain()
  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.")