products.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # -*- coding: utf-8 -*-
  2. # Part of AppJetty. See LICENSE file for full copyright and licensing details.
  3. from openerp import api, fields, models, _
  4. from openerp.exceptions import Warning
  5. from openerp.addons.website_sale.controllers import main
  6. class Brands(models.Model):
  7. _name = 'product.brands'
  8. name = fields.Char(string='Brand Name', required=True, translate=True)
  9. brand_description = fields.Html(string='Description', translate=True)
  10. brand_logo = fields.Binary(string='Brand Logo')
  11. brand_cover = fields.Binary(string='Brand Cover')
  12. product_ids = fields.One2many(
  13. 'product.template',
  14. 'product_brand_id',
  15. string='Product Brands',
  16. )
  17. products_count = fields.Integer(
  18. string='Number of products',
  19. compute='_get_products_count',
  20. )
  21. @api.one
  22. @api.depends('product_ids')
  23. def _get_products_count(self):
  24. self.products_count = len(self.product_ids)
  25. class ProductStyleTags(models.Model):
  26. _name = 'biztech.product.style.tag'
  27. name = fields.Char(string='Tag Name', required=True, translate=True)
  28. color = fields.Selection(
  29. [('red', 'Red'), ('new', 'Green'), ('sale', 'Orange')], string="Color")
  30. product_ids = fields.One2many(
  31. 'product.template',
  32. 'product_style_tag_id',
  33. string='Product Tags',
  34. )
  35. class KingProductImages(models.Model):
  36. _name = 'biztech.product.images'
  37. _description = "Add Multiple Image in Product"
  38. name = fields.Char(string='Title', translate=True)
  39. alt = fields.Char(string='Alt', translate=True)
  40. attach_type = fields.Selection([('image', 'Image'), ('video', 'Video')],
  41. default='image',
  42. string="Type")
  43. image = fields.Binary(string='Image')
  44. video_type = fields.Selection([('youtube', 'Youtube'),
  45. ('vimeo', 'Vimeo'),
  46. ('html5video', 'Html5 Video')],
  47. default='youtube',
  48. string="Video media player")
  49. cover_image = fields.Binary(string='Cover image',
  50. # required=True,
  51. help="Cover Image will be show untill video is loaded.")
  52. video_id = fields.Char(string='Video ID')
  53. video_ogv = fields.Char(string='Video OGV', help="Link for ogv format video")
  54. video_webm = fields.Char(string='Video WEBM', help="Link for webm format video")
  55. video_mp4 = fields.Char(string='Video MP4', help="Link for mp4 format video")
  56. sequence = fields.Integer(string='Sort Order')
  57. product_tmpl_id = fields.Many2one('product.template', string='Product')
  58. more_view_exclude = fields.Boolean(string="More View Exclude")
  59. class ProductTemplate(models.Model):
  60. _inherit = 'product.template'
  61. product_brand_id = fields.Many2one(
  62. 'product.brands',
  63. string='Brand',
  64. help='Select a brand for this product'
  65. )
  66. images = fields.One2many('biztech.product.images', 'product_tmpl_id',
  67. string='Images')
  68. multi_image = fields.Boolean(string="Add Multiple Images?")
  69. tag_ids = fields.Many2many('biztech.product.tags', string="Tags")
  70. is_flip_image = fields. Boolean(
  71. string="Add flip image", help="Enable this checkbox for adding flip image on product website.")
  72. flip_image = fields.Binary(string='Flip image',
  73. help="Flip image will be shown on mouse hover in website on specific product.")
  74. product_style_tag_id = fields.Many2one(
  75. 'biztech.product.style.tag',
  76. string='Tags',
  77. help='Select a tag for this product'
  78. )
  79. class ProductTags(models.Model):
  80. _name = 'biztech.product.tags'
  81. _order = "sequence"
  82. name = fields.Char(string="Tag Name", help="Tag Name", required=True, translate=True)
  83. active = fields.Boolean(
  84. string="Active", help="Enable or Disable tag from website", default=True)
  85. sequence = fields.Integer(
  86. string='Sequence', help="You can define sequence of tags you want to show tags")
  87. product_ids = fields.Many2many('product.template', string='Products', required=True)
  88. _sql_constraints = [('unique_tag_name', 'unique(name)', 'Tag name should be unique..!'), ]
  89. class ProductSortBy(models.Model):
  90. _name = 'biztech.product.sortby'
  91. name = fields.Char(string="Name", help='Name for sorting option', translate=True,
  92. required=True)
  93. sort_type = fields.Selection(
  94. [('asc', 'Ascending'), ('desc', 'Descending')], string="Type", default='asc')
  95. sort_on = fields.Many2one('ir.model.fields', string='Sort On',
  96. help='Select field on which you want to apply sorting',
  97. domain=[('model', '=', 'product.template'), ('ttype', 'in', ('char', 'float', 'integer', 'datetime', 'date'))])
  98. class ProductCategory(models.Model):
  99. _inherit = 'product.public.category'
  100. include_in_megamenu = fields.Boolean(
  101. string="Include in mega menu", help="Include in mega menu")
  102. menu_id = fields.Many2one('website.menu', string="Main menu")
  103. description = fields.Text(string="Description",
  104. help="Short description which will be visible below category slider.")
  105. class ProductPerPageNo(models.Model):
  106. _name = "product.per.page.no"
  107. _order = 'name asc'
  108. name = fields.Integer(string='Product per page')
  109. set_default_check = fields.Boolean(string="Set default")
  110. prod_page_id = fields.Many2one('product.per.page')
  111. @api.model
  112. def create(self, vals):
  113. res = super(ProductPerPageNo, self).create(vals)
  114. if vals.get('name') == 0:
  115. raise Warning(_("Warning! You cannot set 'zero' for product page."))
  116. if vals.get('set_default_check'):
  117. true_records = self.search(
  118. [('set_default_check', '=', True), ('id', '!=', res.id)])
  119. true_records.write({'set_default_check': False})
  120. return res
  121. @api.multi
  122. def write(self, vals):
  123. res = super(ProductPerPageNo, self).write(vals)
  124. if vals.get('name') == 0:
  125. raise Warning(_("Warning! You cannot set 'zero' for product page."))
  126. if vals.get('set_default_check'):
  127. true_records = self.search(
  128. [('set_default_check', '=', True), ('id', '!=', self.id)])
  129. true_records.write({'set_default_check': False})
  130. return res
  131. class ProductPerPage(models.Model):
  132. _name = "product.per.page"
  133. name = fields.Char(string="Label Name", translate=True)
  134. no_ids = fields.One2many(
  135. 'product.per.page.no', 'prod_page_id', string="No of product to display")
  136. @api.multi
  137. def write(self, vals):
  138. res = super(ProductPerPage, self).write(vals)
  139. default_pg = self.env['product.per.page.no'].search([('set_default_check', '=', True)])
  140. if default_pg.name:
  141. main.PPG = int(default_pg.name)
  142. else:
  143. raise Warning(_("Warning! You have to set atleast one default value."))
  144. return res