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