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.0 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Backup Draft Orders module for OpenERP
  5. # Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.osv.orm import Model
  23. class pos_order(Model):
  24. _inherit = 'pos.order'
  25. # custom function
  26. def _create_draft_from_ui(self, cr, uid, orders, context=None):
  27. order_ids = []
  28. for tmp_order in orders:
  29. order = tmp_order['data']
  30. order_id = self.create(cr, uid, {
  31. 'name': order['name'],
  32. 'user_id': order['user_id'] or False,
  33. 'session_id': order['pos_session_id'],
  34. 'lines': order['lines'],
  35. 'pos_reference': order['name'],
  36. 'partner_id': order.get('partner_id', False)
  37. }, context)
  38. for payments in order['statement_ids']:
  39. payment = payments[2]
  40. self.add_payment(cr, uid, order_id, {
  41. 'amount': payment['amount'] or 0.0,
  42. 'payment_date': payment['name'],
  43. 'statement_id': payment['statement_id'],
  44. 'payment_name': payment.get('note', False),
  45. 'journal': payment['journal_id']
  46. }, context=context)
  47. order_ids.append(order_id)
  48. return order_ids
  49. # Overload section
  50. def create_from_ui(self, cr, uid, orders, context=None):
  51. """
  52. - remove from the 'orders' list all orders where amount_return is < 0
  53. (because that means they are not paid, but just saved) and put them
  54. in a 'saved_orders' list
  55. - call a specific function for the 'saved_orders' list
  56. - call the parent create_from_ui() for the remaining orders"""
  57. saved_orders = []
  58. for tmp_order in orders:
  59. if tmp_order['data']['amount_return'] < 0\
  60. and abs(tmp_order['data']['amount_return']) > 0.000001:
  61. saved_orders.append(tmp_order)
  62. orders.remove(tmp_order)
  63. self._create_draft_from_ui(
  64. cr, uid, saved_orders, context=context)
  65. return super(pos_order, self).create_from_ui(
  66. cr, uid, orders, context=context)