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.

79 lines
2.9 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Change Payment module for Odoo
  5. # Copyright (C) 2013-Today GRAP (http://www.grap.coop)
  6. # @author Julien WESTE
  7. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ##############################################################################
  23. from openerp.osv.orm import TransientModel
  24. from openerp.osv import fields
  25. from openerp import netsvc
  26. class pos_make_payment(TransientModel):
  27. _inherit = 'pos.make.payment'
  28. def check(self, cr, uid, ids, context=None):
  29. """Check the order:
  30. if the order is not paid: continue payment,
  31. if the order is paid print ticket.
  32. """
  33. context = context or {}
  34. order_obj = self.pool.get('pos.order')
  35. active_id = context and context.get('active_id', False)
  36. order = order_obj.browse(cr, uid, active_id, context=context)
  37. amount = order.amount_total - order.amount_paid
  38. data = self.read(cr, uid, ids, context=context)[0]
  39. data['journal'] = data['journal_id']
  40. if amount != 0.0:
  41. order_obj.add_payment(cr, uid, active_id, data, context=context)
  42. if order_obj.test_paid(cr, uid, [active_id]):
  43. wf_service = netsvc.LocalService('workflow')
  44. wf_service.trg_validate(uid, 'pos.order', active_id, 'paid', cr)
  45. return {'type': 'ir.actions.act_window_close'}
  46. return self.launch_payment(cr, uid, ids, context=context)
  47. # Selection Section
  48. def _select_journals(self, cr, uid, context=None):
  49. aj_obj = self.pool['account.journal']
  50. return aj_obj._get_pos_journal_selection(cr, uid, context=context)
  51. # Column Section
  52. _columns = {
  53. # Redefine journal_id from many2one to selection
  54. 'journal_id': fields.selection(
  55. _select_journals, 'Journal', required=True, size=-1),
  56. }
  57. # Default Section
  58. def _default_journal(self, cr, uid, context=None):
  59. aj_obj = self.pool['account.journal']
  60. res = aj_obj._get_pos_journal_selection(cr, uid, context=context)
  61. if res and len(res) > 1:
  62. return res[0][0]
  63. else:
  64. return False
  65. _defaults = {
  66. 'journal_id': _default_journal,
  67. }