Kingfisher_theme.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. See LICENSE file for full copyright and licensing details.
  3. from openerp.osv import osv, orm, fields
  4. from datetime import date
  5. from openerp.addons.website.models.website import slugify
  6. class product_template(osv.Model):
  7. _inherit = "product.template"
  8. _columns = {
  9. 'is_arrival':fields.boolean('Arrival Products'),
  10. 'is_features': fields.boolean('Feature Products'),
  11. }
  12. _defaults = {
  13. 'is_arrival':False,
  14. 'is_features':False,
  15. }
  16. product_template()
  17. class res_partner(osv.osv):
  18. _description = 'Supplier Brand'
  19. _inherit = "res.partner"
  20. _columns={
  21. 'is_home_brand':fields.boolean('Brand'),
  22. }
  23. _defaults = {
  24. 'is_home_brand':False,
  25. }
  26. res_partner()
  27. class website(orm.Model):
  28. _inherit = 'website'
  29. def get_arrival_product(self, cr, uid,ids, context=None):
  30. prod_ids=self.pool.get('product.template').search(cr, uid, [('is_arrival','=','True'),("sale_ok", "=", True)], context=context)
  31. if prod_ids and len(prod_ids)>16:
  32. prod_ids=prod_ids[:16]
  33. elif prod_ids and len(prod_ids)<=16:
  34. prod_ids=prod_ids
  35. price_list=self.price_list_get(cr,uid,context);
  36. product_data = self.pool.get('product.template').browse(cr,uid,prod_ids,{'pricelist':int(price_list)})
  37. return product_data
  38. def price_list_get(self,cr,uid,context=None):
  39. partner = self.pool.get('res.users').browse(cr, uid, uid, context=context)
  40. if partner:
  41. price_list=partner.partner_id.property_product_pricelist
  42. return price_list.id
  43. return True
  44. def get_feature_product(self, cr, uid,ids, context=None):
  45. prod_ids=self.pool.get('product.template').search(cr, uid,[('is_features','=','True'),("sale_ok", "=", True)], context=context)
  46. if prod_ids and len(prod_ids)>8:
  47. prod_ids=prod_ids[:8]
  48. elif prod_ids and len(prod_ids)<=8:
  49. prod_ids=prod_ids
  50. price_list=self.price_list_get(cr,uid,context);
  51. product_data = self.pool.get('product.template').browse(cr,uid,prod_ids,{'pricelist':int(price_list)})
  52. return product_data
  53. def get_brand_img(self, cr, uid,ids, context=None):
  54. brand_ids=self.pool.get('res.partner').search(cr, uid, [('is_home_brand','=','True')], context=context)
  55. brand_data = self.pool.get('res.partner').browse(cr,uid,brand_ids,context)
  56. return brand_data
  57. def get_current_year(self):
  58. return date.today().year
  59. def new_page(self, cr, uid, name, template='website.default_page', ispage=True, context=None):
  60. context = context or {}
  61. imd = self.pool.get('ir.model.data')
  62. view = self.pool.get('ir.ui.view')
  63. template_module, template_name = template.split('.')
  64. # completely arbitrary max_length
  65. page_name = slugify(name, max_length=50)
  66. page_xmlid = "%s.%s" % (template_module, page_name)
  67. try:
  68. # existing page
  69. imd.get_object_reference(cr, uid, template_module, page_name)
  70. except ValueError:
  71. # new page
  72. _, template_id = imd.get_object_reference(cr, uid, template_module, template_name)
  73. page_id = view.copy(cr, uid, template_id, context=context)
  74. page = view.browse(cr, uid, page_id, context=context)
  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
  100. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: