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.

31 lines
1.1 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. class PosOrder(models.Model):
  7. _inherit = 'pos.order'
  8. loyalty_points = fields.Float(string='Loyalty Points',
  9. help='The amount of Loyalty points awarded '
  10. 'to the customer with this order')
  11. @api.model
  12. def _order_fields(self, ui_order):
  13. res = super(PosOrder, self)._order_fields(ui_order)
  14. res['loyalty_points'] = ui_order.get('loyalty_points', 0)
  15. return res
  16. @api.model
  17. def create_from_ui(self, orders):
  18. res = super(PosOrder, self).create_from_ui(orders)
  19. for order in orders:
  20. order_partner = order['data']['partner_id']
  21. order_points = order['data']['loyalty_points']
  22. if order_points != 0 and order_partner:
  23. partner = self.env['res.partner'].browse(order_partner)
  24. partner.loyalty_points += order_points
  25. return res