main.py 19 KB

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