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.

68 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2004-2010 OpenERP SA
  3. # Copyright 2017 RGB Consulting S.L. (https://www.rgbconsulting.com)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import fields, models, api, _
  6. from odoo.exceptions import ValidationError
  7. class LoyaltyReward(models.Model):
  8. _name = 'loyalty.reward'
  9. name = fields.Char(string='Reward Name', size=32, index=True,
  10. required=True)
  11. type = fields.Selection(selection=[('gift', 'Gift'),
  12. ('discount', 'Discount'),
  13. ('resale', 'Resale')],
  14. string='Type', required=True,
  15. help='Type of the reward')
  16. minimum_points = fields.Float(string='Minimum Points',
  17. help='Minimum amount of points the customer'
  18. ' must have to qualify for this reward')
  19. point_cost = fields.Float(string='Point Cost',
  20. help='Cost of the reward per monetary unit '
  21. 'discounted')
  22. discount = fields.Float(help='The discount percentage')
  23. discount_max = fields.Float(string='Discount limit',
  24. help='Maximum discounted amount allowed for'
  25. 'this discount reward')
  26. loyalty_program_id = fields.Many2one(comodel_name='loyalty.program',
  27. string='Loyalty Program',
  28. help='The Loyalty Program this reward'
  29. ' belongs to')
  30. gift_product_id = fields.Many2one(comodel_name='product.product',
  31. string='Gift Product',
  32. help='The product given as a reward')
  33. discount_product_id = fields.Many2one(comodel_name='product.product',
  34. string='Discount Product',
  35. help='The product used to apply '
  36. 'discounts')
  37. point_product_id = fields.Many2one(comodel_name='product.product',
  38. string='Point Product',
  39. help='Product that represents a point '
  40. 'that is sold by the customer')
  41. @api.multi
  42. @api.constrains('type', 'gift_product_id')
  43. def _check_gift_product(self):
  44. for reward in self:
  45. if reward.type == 'gift' and not reward.gift_product_id:
  46. raise ValidationError(
  47. _('Gift product field is mandatory for gift rewards'))
  48. @api.multi
  49. @api.constrains('type', 'discount_product_id')
  50. def _check_discount_product(self):
  51. for reward in self:
  52. if reward.type == 'discount' and not reward.discount_product_id:
  53. raise ValidationError(_('Discount product field is '
  54. 'mandatory for discount rewards'))
  55. @api.multi
  56. @api.constrains('type', 'point_product_id')
  57. def _check_point_product(self):
  58. for reward in self:
  59. if reward.type == 'resale' and not reward.point_product_id:
  60. raise ValidationError(_('Point product field is '
  61. 'mandatory for point resale rewards'))