website.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. # -*- coding: utf-8 -*-
  2. # Part of AppJetty. 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. def pager(self, cr, uid, ids, url, total, page=1, step=30, scope=5, url_args=None, context=None):
  96. res = super(website, self). pager(cr, uid, ids, url=url,
  97. total=total,
  98. page=page,
  99. step=step,
  100. scope=scope,
  101. url_args=url_args,
  102. context=context)
  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:
  114. if url_args.get('tag'):
  115. del url_args['tag']
  116. if url_args.get('range1'):
  117. del url_args['range1']
  118. if url_args.get('range2'):
  119. del url_args['range2']
  120. if url_args.get('max1'):
  121. del url_args['max1']
  122. if url_args.get('min1'):
  123. del url_args['min1']
  124. if url_args.get('sort_id'):
  125. del url_args['sort_id']
  126. if 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'):
  127. _url = "%s?%s" % (_url, werkzeug.url_encode(url_args))
  128. return _url
  129. res.update({
  130. # Overrite existing
  131. "page_start": {
  132. 'url': get_url(pmin),
  133. 'num': pmin
  134. },
  135. "page_previous": {
  136. 'url': get_url(max(pmin, page - 1)),
  137. 'num': max(pmin, page - 1)
  138. },
  139. "page_next": {
  140. 'url': get_url(min(pmax, page + 1)),
  141. 'num': min(pmax, page + 1)
  142. },
  143. "page_end": {
  144. 'url': get_url(pmax),
  145. 'num': pmax
  146. },
  147. 'page_first': {
  148. 'url': get_url(1),
  149. 'num': 1
  150. },
  151. 'page_last': {
  152. 'url': get_url(int(res['page_count'])),
  153. 'num': int(res['page_count'])
  154. },
  155. 'pages': [
  156. {'url': get_url(page), 'num': page}
  157. for page in range(pmin, pmax+1)
  158. ]
  159. })
  160. return res
  161. # For multi image
  162. @api.multi
  163. def get_multiple_images(self, product_id=None):
  164. product_img_data = False
  165. if product_id:
  166. self.env.cr.execute(
  167. "select id from biztech_product_images where product_tmpl_id=%s and more_view_exclude IS NOT TRUE order by sequence", ([product_id]))
  168. product_ids = map(lambda x: x[0], self.env.cr.fetchall())
  169. if product_ids:
  170. product_img_data = self.env['biztech.product.images'].browse(
  171. product_ids)
  172. return product_img_data
  173. # For brands
  174. def sale_product_domain(self, cr, uid, ids, context=None):
  175. domain = super(website, self).sale_product_domain(cr, uid, ids=ids,
  176. context=context)
  177. if 'brand_id' in request.context:
  178. domain.append(
  179. ('product_brand_id', '=', request.context['brand_id']))
  180. return domain
  181. # For product tags feature
  182. def get_product_tags(self):
  183. product_tags = self.env['biztech.product.tags'].search([])
  184. return product_tags
  185. # For Sorting products
  186. def get_sort_by_data(self):
  187. request.session['product_sort_name'] = ''
  188. sort_by = self.env['biztech.product.sortby'].search([])
  189. return sort_by
  190. # For setting current sort list
  191. def set_current_sorting_data(self):
  192. sort_name = request.session.get('product_sort_name')
  193. return sort_name
  194. # For megamenu
  195. @api.multi
  196. def get_public_product_category(self, submenu):
  197. categories = self.env['product.public.category'].search([('parent_id', '=', False),
  198. ('include_in_megamenu',
  199. '!=', False),
  200. ('menu_id', '=', submenu.id)],
  201. order="sequence")
  202. return categories
  203. def get_public_product_child_category(self, children):
  204. child_categories = []
  205. for child in children:
  206. categories = self.env['product.public.category'].search([
  207. ('id', '=', child.id),
  208. ('include_in_megamenu', '!=', False)], order="sequence")
  209. if categories:
  210. child_categories.append(categories)
  211. return child_categories
  212. class WebsiteConfigSettings(models.TransientModel):
  213. _inherit = 'website.config.settings'
  214. # For multi image
  215. thumbnail_panel_position = fields.Selection([
  216. ('left', 'Left'),
  217. ('right', 'Right'),
  218. ('bottom', 'Bottom')],
  219. string='Thumbnails panel position',
  220. related='website_id.thumbnail_panel_position',
  221. help="Select the position where you want to display the thumbnail panel in multi image.")
  222. interval_play = fields.Char(string='Play interval of slideshow',
  223. related='website_id.interval_play',
  224. help='With this field you can set the interval play time between two images.')
  225. enable_disable_text = fields.Boolean(string='Enable the text panel',
  226. related='website_id.enable_disable_text',
  227. help='Enable/Disable text which is visible on the image in multi image.')
  228. color_opt_thumbnail = fields.Selection([
  229. ('default', 'Default'),
  230. ('b_n_w', 'B/W'),
  231. ('sepia', 'Sepia'),
  232. ('blur', 'Blur')],
  233. related='website_id.color_opt_thumbnail',
  234. string="Thumbnail overlay effects")
  235. no_extra_options = fields.Boolean(string='Slider effects',
  236. # default=True,
  237. related='website_id.no_extra_options',
  238. help="Slider with all options for next, previous, play, pause, fullscreen, hide/show thumbnail panel.")
  239. change_thumbnail_size = fields.Boolean(string="Change thumbnail size",
  240. related="website_id.change_thumbnail_size"
  241. )
  242. thumb_height = fields.Char(string='Thumb height',
  243. related="website_id.thumb_height"
  244. )
  245. thumb_width = fields.Char(string='Thumb width',
  246. related="website_id.thumb_width"
  247. )
  248. # For Sort By
  249. enable_sort_by = fields.Boolean(related="website_id.enable_sort_by", string='Enable product sorting option',
  250. help='For enabling product sorting feature in website.',
  251. default=True)
  252. # For first last pager
  253. enable_first_last_pager = fields.Boolean(related='website_id.enable_first_last_pager',
  254. string="Enable First and Last Pager", default=True,
  255. help="Enable this checkbox to make 'First' and 'Last' button in pager on website.")
  256. # Product per grid
  257. product_display_grid = fields.Selection(related='website_id.product_display_grid',
  258. default='3', string='Product per grid', help="Display no. of products per line in website product grid.")