pos_order_line.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models
  4. class PosOrderLine(models.Model):
  5. _inherit = 'pos.order.line'
  6. is_reward_line = fields.Boolean(
  7. help="Whether this line is part of a reward or not.")
  8. reward_id = fields.Many2one(
  9. 'loyalty.reward', "Reward", ondelete='restrict',
  10. help="The reward associated with this line.")
  11. coupon_id = fields.Many2one(
  12. 'loyalty.card', "Coupon", ondelete='restrict',
  13. help="The coupon used to claim that reward.")
  14. reward_identifier_code = fields.Char(help="""
  15. Technical field used to link multiple reward lines from the same reward together.
  16. """)
  17. points_cost = fields.Float(help="How many point this reward cost on the coupon.")
  18. def _order_line_fields(self, line, session_id=None):
  19. res = super()._order_line_fields(line, session_id)
  20. # coupon_id may be negative in case of new coupons, they will be added after validating the order.
  21. if 'coupon_id' in res[2] and res[2]['coupon_id'] < 1:
  22. res[2].pop('coupon_id')
  23. return res
  24. def _is_not_sellable_line(self):
  25. return super().is_not_sellable_line() or self.reward_id
  26. def _export_for_ui(self, orderline):
  27. result = super()._export_for_ui(orderline)
  28. result['is_reward_line'] = orderline.is_reward_line
  29. result['reward_id'] = orderline.reward_id.id
  30. return result