Kingfisher_theme.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. See LICENSE file for full copyright and licensing details.
  3. from datetime import date
  4. import openerp
  5. from openerp import api, fields, models, _
  6. from openerp.http import request
  7. from openerp.addons.website.models.website import slugify
  8. class product_template(models.Model):
  9. _inherit = "product.template"
  10. is_arrival = fields.Boolean(string='Arrival Products', default=False)
  11. is_features = fields.Boolean(string='Feature Products', default=False)
  12. class res_partner(models.Model):
  13. _description = 'Supplier Brand'
  14. _inherit = "res.partner"
  15. is_home_brand = fields.Boolean(string='Brand', default=False)
  16. class website(models.Model):
  17. _inherit = 'website'
  18. def get_arrival_product(self):
  19. template_obj = self.env['product.template']
  20. prod_ids = template_obj.search(
  21. [('is_arrival', '=', 'True'), ("sale_ok", "=", True)])
  22. if prod_ids and len(prod_ids) > 16:
  23. prod_ids = prod_ids[:16]
  24. elif prod_ids and len(prod_ids) <= 16:
  25. prod_ids = prod_ids
  26. price_list = self.price_list_get()
  27. return prod_ids
  28. def price_list_get(self):
  29. user = request.env.user
  30. if user:
  31. price_list = user.partner_id.property_product_pricelist
  32. return price_list.id
  33. return True
  34. def get_feature_product(self):
  35. template_obj = self.env['product.template']
  36. prod_ids = template_obj.search([('is_features', '=', 'True'),
  37. ("sale_ok", "=", True)])
  38. if prod_ids and len(prod_ids) > 8:
  39. prod_ids = prod_ids[:8]
  40. elif prod_ids and len(prod_ids) <= 8:
  41. prod_ids = prod_ids
  42. price_list = self.price_list_get()
  43. return prod_ids
  44. def get_brand_img(self):
  45. partner_obj = self.env['res.partner']
  46. brands = partner_obj.search([('is_home_brand', '=', 'True')])
  47. return brands
  48. def get_current_year(self):
  49. return date.today().year
  50. def new_page(self, cr, uid, name, template='website.default_page', ispage=True, context=None):
  51. context = context or {}
  52. imd = self.pool.get('ir.model.data')
  53. view = self.pool.get('ir.ui.view')
  54. template_module, template_name = template.split('.')
  55. # completely arbitrary max_length
  56. page_name = slugify(name, max_length=50)
  57. page_xmlid = "%s.%s" % (template_module, page_name)
  58. # find a free xmlid
  59. inc = 0
  60. dom = [('website_id', '=', False), ('website_id', '=', context.get('website_id'))]
  61. while view.search(cr, openerp.SUPERUSER_ID, [('key', '=', page_xmlid), '|'] + dom, context=dict(context or {}, active_test=False)):
  62. inc += 1
  63. page_xmlid = "%s.%s" % (template_module, page_name + (inc and "-%s" % inc or ""))
  64. page_name += (inc and "-%s" % inc or "")
  65. try:
  66. # existing page
  67. imd.get_object_reference(cr, uid, template_module, page_name)
  68. except ValueError:
  69. # new page
  70. _, template_id = imd.get_object_reference(cr, uid, template_module, template_name)
  71. website_id = context.get('website_id')
  72. key = template_module+'.'+page_name
  73. page_id = view.copy(cr, uid, template_id, {'website_id': website_id, 'key': key}, context=context)
  74. page = view.browse(cr, uid, page_id, context=dict(context, lang=None))
  75. page.write({
  76. 'arch': page.arch.replace(template, page_xmlid),
  77. 'name': page_name,
  78. 'page': ispage,
  79. })
  80. page1 = view.browse(cr, uid, page_id, context=context)
  81. arch = '<?xml version="1.0"?><t t-name="website.'+str(page_name)+'"><t t-call="website.layout"> \
  82. <div id="wrap" class="oe_structure oe_empty"><div class="page-title"><div class="container">\
  83. <h1>'+str(page_name.capitalize())+'</h1> \
  84. <ul class="breadcrumb"><li><a href="/page/homepage">Home</a>\
  85. </li><li class="active">'+str(page_name.capitalize())+'</li></ul></div></div></div></t></t>'
  86. page1.write({'arch': arch})
  87. imd.create(cr, uid, {
  88. 'name': page_name,
  89. 'module': template_module,
  90. 'model': 'ir.ui.view',
  91. 'res_id': page_id,
  92. 'noupdate': True
  93. }, context=context)
  94. return page_xmlid
  95. def get_default_newsletter(self):
  96. data = self.env['mail.mass_mailing.list'].search([], order='id')
  97. if data:
  98. return data[0]
  99. return False