products.py 7.5 KB

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