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.

73 lines
3.7 KiB

  1. # Copyright 2004-2010 OpenERP SA
  2. # Copyright 2017 RGB Consulting S.L. (https://www.rgbconsulting.com)
  3. # Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.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. domain=[('available_in_pos', '=', True)],
  32. string='Gift Product',
  33. help='The product given as a reward')
  34. discount_product_id = fields.Many2one(comodel_name='product.product',
  35. domain=[
  36. ('available_in_pos', '=', True)],
  37. string='Discount Product',
  38. help='The product used to apply '
  39. 'discounts')
  40. point_product_id = fields.Many2one(comodel_name='product.product',
  41. domain=[
  42. ('available_in_pos', '=', True)],
  43. string='Point Product',
  44. help='Product that represents a point '
  45. 'that is sold by the customer')
  46. @api.multi
  47. @api.constrains('type', 'gift_product_id')
  48. def _check_gift_product(self):
  49. for reward in self:
  50. if reward.type == 'gift' and not reward.gift_product_id:
  51. raise ValidationError(
  52. _('Gift product field is mandatory for gift rewards'))
  53. @api.multi
  54. @api.constrains('type', 'discount_product_id')
  55. def _check_discount_product(self):
  56. for reward in self:
  57. if reward.type == 'discount' and not reward.discount_product_id:
  58. raise ValidationError(_('Discount product field is '
  59. 'mandatory for discount rewards'))
  60. @api.multi
  61. @api.constrains('type', 'point_product_id')
  62. def _check_point_product(self):
  63. for reward in self:
  64. if reward.type == 'resale' and not reward.point_product_id:
  65. raise ValidationError(_('Point product field is '
  66. 'mandatory for point resale rewards'))