main.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. # -*- coding: utf-8 -*-
  2. # Part of AppJetty. See LICENSE file for full copyright and licensing details.
  3. import re
  4. from odoo import http
  5. from odoo.http import request
  6. from odoo.addons.website.models.website import slug
  7. from odoo.addons.website.controllers.main import QueryURL
  8. from odoo.addons.website_sale.controllers import main
  9. from odoo.addons.website_sale.controllers import main as main_shop
  10. from odoo.addons.website_sale.controllers.main import WebsiteSale
  11. from odoo.addons.website_sale.controllers.main import TableCompute
  12. from odoo import http,SUPERUSER_ID
  13. class KingfisherProSliderSettings(http.Controller):
  14. @http.route(['/kingfisher_pro/pro_get_options'], type='json', auth="public", website=True)
  15. def get_slider_options(self):
  16. slider_options = []
  17. option = request.env['product.category.slider.config'].search(
  18. [('active', '=', True)], order="name asc")
  19. for record in option:
  20. slider_options.append({'id': record.id,
  21. 'name': record.name})
  22. return slider_options
  23. @http.route(['/kingfisher_pro/pro_get_dynamic_slider'], type='http', auth='public', website=True)
  24. def get_dynamic_slider(self, **post):
  25. uid, context, pool = request.uid, dict(request.context), request.env
  26. if post.get('slider-type'):
  27. slider_header = request.env['product.category.slider.config'].sudo().search(
  28. [('id', '=', int(post.get('slider-type')))])
  29. if not context.get('pricelist'):
  30. pricelist = request.website.get_current_pricelist()
  31. context = dict(request.context, pricelist=int(pricelist))
  32. else:
  33. pricelist = pool.get('product.pricelist').browse(context['pricelist'])
  34. context.update({'pricelist': pricelist.id})
  35. values = {
  36. 'slider_header': slider_header
  37. }
  38. if slider_header.prod_cat_type == 'product':
  39. values.update({'slider_details': slider_header.collections_product})
  40. if slider_header.prod_cat_type == 'category':
  41. values.update({'slider_details': slider_header.collections_category})
  42. from_currency = pool['res.users'].browse(uid).company_id.currency_id
  43. to_currency = pricelist.currency_id
  44. compute_currency = lambda price: pool['res.currency']._compute(from_currency, to_currency, price)
  45. values.update({'slider_type': slider_header.prod_cat_type,
  46. 'compute_currency': compute_currency,})
  47. return request.render("kingfisher_pro.kingfisher_pro_pro_cat_slider_view", values)
  48. @http.route(['/kingfisher_pro/pro_image_effect_config'], type='json', auth='public', website=True)
  49. def product_image_dynamic_slider(self, **post):
  50. slider_data = request.env['product.category.slider.config'].search(
  51. [('id', '=', int(post.get('slider_type')))])
  52. values = {
  53. 's_id': slider_data.prod_cat_type + str(slider_data.id),
  54. 'counts': slider_data.no_of_counts,
  55. 'auto_rotate': slider_data.auto_rotate,
  56. 'auto_play_time': slider_data.sliding_speed,
  57. }
  58. return values
  59. @http.route(['/kingfisher_pro/blog_get_options'], type='json', auth="public", website=True)
  60. def king_blog_get_slider_options(self):
  61. slider_options = []
  62. option = request.env['blog.slider.config'].search(
  63. [('active', '=', True)], order="name asc")
  64. for record in option:
  65. slider_options.append({'id': record.id,
  66. 'name': record.name})
  67. return slider_options
  68. @http.route(['/kingfisher_pro/blog_get_dynamic_slider'], type='http', auth='public', website=True)
  69. def king_blog_get_dynamic_slider(self, **post):
  70. if post.get('slider-type'):
  71. slider_header = request.env['blog.slider.config'].sudo().search(
  72. [('id', '=', int(post.get('slider-type')))])
  73. values = {
  74. 'slider_header': slider_header,
  75. 'blog_slider_details': slider_header.collections_blog_post,
  76. }
  77. return request.render("kingfisher_pro.kingfisher_pro_blog_slider_view", values)
  78. @http.route(['/kingfisher_pro/blog_image_effect_config'], type='json', auth='public', website=True)
  79. def king_blog_product_image_dynamic_slider(self, **post):
  80. slider_data = request.env['blog.slider.config'].search(
  81. [('id', '=', int(post.get('slider_type')))])
  82. values = {
  83. 's_id': slider_data.no_of_counts + '-' + str(slider_data.id),
  84. 'counts': slider_data.no_of_counts,
  85. 'auto_rotate': slider_data.auto_rotate,
  86. 'auto_play_time': slider_data.sliding_speed,
  87. }
  88. return values
  89. # Multi image gallery
  90. @http.route(['/kingfisher_pro/multi_image_effect_config'], type='json', auth="public", website=True)
  91. def get_multi_image_effect_config(self):
  92. cur_website = request.website
  93. values = {
  94. 'no_extra_options': cur_website.no_extra_options,
  95. 'theme_panel_position': cur_website.thumbnail_panel_position,
  96. 'interval_play': cur_website.interval_play,
  97. 'enable_disable_text': cur_website.enable_disable_text,
  98. 'color_opt_thumbnail': cur_website.color_opt_thumbnail,
  99. 'change_thumbnail_size': cur_website.change_thumbnail_size,
  100. 'thumb_height': cur_website.thumb_height,
  101. 'thumb_width': cur_website.thumb_width,
  102. }
  103. return values
  104. # For multi product slider
  105. @http.route(['/kingfisher_pro/product_multi_get_options'], type='json', auth="public", website=True)
  106. def product_multi_get_slider_options(self):
  107. slider_options = []
  108. option = request.env['multi.slider.config'].search(
  109. [('active', '=', True)], order="name asc")
  110. for record in option:
  111. slider_options.append({'id': record.id,
  112. 'name': record.name})
  113. return slider_options
  114. @http.route(['/kingfisher_pro/product_multi_get_dynamic_slider'], type='http', auth='public', website=True)
  115. def product_multi_get_dynamic_slider(self, **post):
  116. context, pool = dict(request.context), request.env
  117. if post.get('slider-type'):
  118. slider_header = request.env['multi.slider.config'].sudo().search(
  119. [('id', '=', int(post.get('slider-type')))])
  120. if not context.get('pricelist'):
  121. pricelist = request.website.get_current_pricelist()
  122. context = dict(request.context, pricelist=int(pricelist))
  123. else:
  124. pricelist = pool.get('product.pricelist').browse(context['pricelist'])
  125. context.update({'pricelist': pricelist.id})
  126. from_currency = pool['res.users'].sudo().browse(SUPERUSER_ID).company_id.currency_id
  127. to_currency = pricelist.currency_id
  128. compute_currency = lambda price: pool['res.currency']._compute(from_currency, to_currency, price)
  129. values = {
  130. 'slider_details': slider_header,
  131. 'slider_header': slider_header,
  132. 'compute_currency': compute_currency,
  133. }
  134. return request.render("kingfisher_pro.kingfisher_pro_multi_cat_slider_view", values)
  135. @http.route(['/kingfisher_pro/product_multi_image_effect_config'], type='json', auth='public', website=True)
  136. def product_multi_product_image_dynamic_slider(self, **post):
  137. slider_data = request.env['multi.slider.config'].search(
  138. [('id', '=', int(post.get('slider_type')))])
  139. values = {
  140. 's_id': slider_data.no_of_collection + '-' + str(slider_data.id),
  141. 'counts': slider_data.no_of_collection,
  142. 'auto_rotate': slider_data.auto_rotate,
  143. 'auto_play_time': slider_data.sliding_speed,
  144. }
  145. return values
  146. class KingfisherProBrandSlider(WebsiteSale):
  147. @http.route(['/shop/pager_selection/<model("product.per.page.no"):pl_id>'], type='http', auth="public", website=True)
  148. def product_page_change(self, pl_id, **post):
  149. request.session['default_paging_no'] = pl_id.name
  150. main.PPG = pl_id.name
  151. return request.redirect('/shop' or request.httprequest.referrer)
  152. @http.route(['/shop',
  153. '/shop/page/<int:page>',
  154. '/shop/category/<model("product.public.category"):category>',
  155. '/shop/category/<model("product.public.category"):category>/page/<int:page>',
  156. '/shop/brands'],
  157. type='http',
  158. auth='public',
  159. website=True)
  160. def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post):
  161. if brand:
  162. req_ctx = request.context.copy()
  163. req_ctx.setdefault('brand_id', int(brand))
  164. request.context = req_ctx
  165. result = super(KingfisherProBrandSlider, self).shop(
  166. page=page, category=category, brand=brand, search=search, **post)
  167. sort_order = ""
  168. cat_id = []
  169. page_no = request.env['product.per.page.no'].search([('set_default_check', '=', True)])
  170. if page_no:
  171. ppg = page_no.name
  172. else:
  173. ppg = main_shop.PPG
  174. product_tmp = []
  175. newproduct = []
  176. product_price = []
  177. # product template object
  178. product_obj = request.env['product.template']
  179. attrib_list = request.httprequest.args.getlist('attrib')
  180. attrib_values = [map(int, v.split("-")) for v in attrib_list if v]
  181. attributes_ids = set([v[0] for v in attrib_values])
  182. attrib_set = set([v[1] for v in attrib_values])
  183. domain = request.website.sale_product_domain()
  184. domain += self._get_search_domain(search, category, attrib_values)
  185. url = "/shop"
  186. keep = QueryURL('/shop', category=category and int(category), search=search,
  187. attrib=attrib_list, order=post.get('order'))
  188. if post:
  189. request.session.update(post)
  190. if search:
  191. post["search"] = search
  192. if attrib_list:
  193. post['attrib'] = attrib_list
  194. prevurl = request.httprequest.referrer
  195. if prevurl:
  196. if not re.search('/shop', prevurl, re.IGNORECASE):
  197. request.session['tag'] = ""
  198. request.session['sort_id'] = ""
  199. request.session['sortid'] = ""
  200. request.session['pricerange'] = ""
  201. request.session['min1'] = ""
  202. request.session['max1'] = ""
  203. session = request.session
  204. # for category filter
  205. if category:
  206. category = request.env['product.public.category'].browse(int(category))
  207. url = "/shop/category/%s" % slug(category)
  208. if category != None:
  209. for ids in category:
  210. cat_id.append(ids.id)
  211. domain += ['|', ('public_categ_ids.id', 'in', cat_id),
  212. ('public_categ_ids.parent_id', 'in', cat_id)]
  213. # for tag filter
  214. if session.get('tag'):
  215. session_tag = session.get('tag')[0]
  216. tag = session_tag
  217. if tag:
  218. tag = request.env['biztech.product.tags'].browse(int(tag))
  219. domain += [('biztech_tag_ids', '=', int(tag))]
  220. request.session["tag"] = [tag.id, tag.name]
  221. # For Product Sorting
  222. if session.get('sort_id'):
  223. session_sort = session.get('sort_id')
  224. sort = session_sort
  225. sort_field = request.env['biztech.product.sortby'].browse(int(sort))
  226. request.session['product_sort_name'] = sort_field.name
  227. order_field = sort_field.sort_on.name
  228. order_type = sort_field.sort_type
  229. sort_order = '%s %s' % (order_field, order_type)
  230. if post.get("sort_id"):
  231. request.session["sortid"] = [sort, sort_order, sort_field.name, order_type]
  232. # For Price slider
  233. product_slider_ids = []
  234. asc_product_slider_ids = product_obj.search([('website_published', '=', True)], limit=1, order='list_price')
  235. desc_product_slider_ids = product_obj.search([('website_published', '=', True)], limit=1, order='list_price desc')
  236. if asc_product_slider_ids:
  237. product_slider_ids.append(asc_product_slider_ids.website_price)
  238. if desc_product_slider_ids:
  239. product_slider_ids.append(desc_product_slider_ids.website_price)
  240. if product_slider_ids:
  241. if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"):
  242. range1 = min(product_slider_ids)
  243. range2 = max(product_slider_ids)
  244. result.qcontext['range1'] = range1
  245. result.qcontext['range2'] = range2
  246. if session.get("min1") and session["min1"]:
  247. post["min1"] = session["min1"]
  248. if session.get("max1") and session["max1"]:
  249. post["max1"] = session["max1"]
  250. if range1:
  251. post["range1"] = range1
  252. if range2:
  253. post["range2"] = range2
  254. if range1 == range2:
  255. post['range1'] = 0.0
  256. if request.session.get('min1') or request.session.get('max1'):
  257. if request.session.get('min1'):
  258. if request.session['min1'] != None:
  259. domain += [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1'))]
  260. request.session["pricerange"] = str(
  261. request.session['min1'])+"-To-"+str(request.session['max1'])
  262. if session.get('min1') and session['min1']:
  263. result.qcontext['min1'] = session["min1"]
  264. result.qcontext['max1'] = session["max1"]
  265. if request.session.get('default_paging_no'):
  266. ppg = int(request.session.get('default_paging_no'))
  267. product_count = product_obj.search_count(domain)
  268. pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
  269. products = product_obj.search(domain, limit=ppg, offset=pager['offset'], order=sort_order)
  270. result.qcontext.update({'product_count': product_count,
  271. 'products': products,
  272. 'category': category,
  273. 'pager': pager,
  274. 'keep':keep,
  275. 'search':search,
  276. 'bins': TableCompute().process(products, ppg)})
  277. result.qcontext['brand'] = brand
  278. result.qcontext['brand_obj'] = request.env['product.brands'].search([('id', '=', brand)])
  279. return result
  280. @http.route()
  281. def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
  282. result = super(KingfisherProBrandSlider, self).cart_update_json(
  283. product_id, line_id, add_qty, set_qty, display)
  284. order = request.website.sale_get_order()
  285. result.update({'kingfisher_pro.hover_total': request.env['ir.ui.view'].render_template("kingfisher_pro.hover_total", {
  286. 'website_sale_order': order })
  287. })
  288. return result
  289. @http.route(['/king_pro/get_brand_slider'], type='http', auth='public', website=True)
  290. def get_brand_slider(self, **post):
  291. keep = QueryURL('/king_pro/get_brand_slider', brand_id=[])
  292. value = {
  293. 'website_brands': False,
  294. 'brand_header': False,
  295. 'keep': keep
  296. }
  297. if post.get('product_count'):
  298. brand_data = request.env['product.brands'].search(
  299. [], limit=int(post.get('product_count')))
  300. if brand_data:
  301. value['website_brands'] = brand_data
  302. if post.get('product_label'):
  303. value['brand_header'] = post.get('product_label')
  304. return request.render("kingfisher_pro.kingfisher_pro_brand_slider_view", value)
  305. @http.route(['/kingfisher_pro/removeattribute'], type='json', auth='public', website=True)
  306. def remove_selected_attribute(self, **post):
  307. if post.get("attr_remove"):
  308. remove = post.get("attr_remove")
  309. if remove == "pricerange":
  310. del request.session['min1']
  311. del request.session['max1']
  312. request.session[remove] = ''
  313. return True
  314. elif remove == "sortid":
  315. request.session[remove] = ''
  316. request.session["sort_id"] = ''
  317. return True
  318. elif remove == "tag":
  319. request.session[remove] = ''
  320. return True