Kingfisher_theme.py~ 4.6 KB

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