website.py 13 KB

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