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.

30 lines
1.1 KiB

  1. # Copyright 2004-2010 OpenERP SA
  2. # Copyright 2017 RGB Consulting S.L. (https://www.rgbconsulting.com)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import fields, models, api
  5. class PosOrder(models.Model):
  6. _inherit = 'pos.order'
  7. loyalty_points = fields.Float(string='Loyalty Points',
  8. help='The amount of Loyalty points awarded '
  9. 'to the customer with this order')
  10. @api.model
  11. def _order_fields(self, ui_order):
  12. res = super(PosOrder, self)._order_fields(ui_order)
  13. res['loyalty_points'] = ui_order.get('loyalty_points', 0)
  14. return res
  15. @api.model
  16. def create_from_ui(self, orders):
  17. res = super(PosOrder, self).create_from_ui(orders)
  18. for order in orders:
  19. order_partner = order['data']['partner_id']
  20. order_points = order['data'].get('loyalty_points', 0)
  21. if order_points != 0 and order_partner:
  22. partner = self.env['res.partner'].browse(order_partner)
  23. partner.loyalty_points += order_points
  24. return res