You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>).
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import models, fields, api, tools
  5. class ProductTemplate(models.Model):
  6. _inherit = 'product.template'
  7. pos_categ_id = fields.Many2one('product.category',
  8. store=False,
  9. related='categ_id',
  10. search='_search_pos_categ_id')
  11. @api.multi
  12. def _search_pos_categ_id(self, operator, value):
  13. return [('categ_id', operator, value)]
  14. @api.model
  15. def create(self, vals):
  16. if 'categ_id' in vals:
  17. vals['pos_categ_id'] = vals['categ_id']
  18. return super(ProductTemplate, self).create(vals)
  19. @api.multi
  20. def write(self, vals):
  21. if 'pos_categ_id' in vals and not vals['pos_categ_id']:
  22. del vals['pos_categ_id']
  23. return super(ProductTemplate, self).write(vals)
  24. class ProductCategory(models.Model):
  25. _inherit = 'product.category'
  26. image = fields.Binary(help='Show Image Category in Form View')
  27. image_medium = fields.Binary(help='Show image category button in POS',
  28. compute="_compute_image",
  29. inverse="_set_image",
  30. store=True)
  31. available_in_pos = fields.Boolean(
  32. string="Available in the Point of Sale",
  33. default=True,
  34. help="Check if you want this category to appear in Point Of Sale.\n"
  35. "If you uncheck, children categories will becomes invisible too, "
  36. "whatever their checkbox state.")
  37. @api.multi
  38. def _compute_image(self):
  39. return dict(
  40. (rec.id, tools.image_get_resized_images(rec.image)) for rec in
  41. self)
  42. @api.one
  43. def _set_image(self):
  44. return self.write(
  45. {'image': tools.image_resize_image_big(self.image_medium)})