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.

59 lines
2.4 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. # 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 account_journal(Model):
  24. _inherit = 'account.journal'
  25. # Private Function Section
  26. def _get_pos_journal_selection(
  27. self, cr, uid, context=None):
  28. """Return Account Journal available for payment in PoS Module"""
  29. if not context or not context.get('pos_session_id', False):
  30. return False
  31. aj_obj = self.pool['account.journal']
  32. ps_obj = self.pool['pos.session']
  33. # Get Session of the Current PoS
  34. ps = ps_obj.browse(
  35. cr, uid, context.get('pos_session_id'), context=context)
  36. aj_ids = [j.id for j in ps.journal_ids]
  37. # Get Journals, order by type (cash before), and name
  38. aj_cash_ids = aj_obj.search(cr, uid, [
  39. ('id', 'in', aj_ids), ('type', '=', 'cash')], context=context)
  40. cash_res = aj_obj.read(
  41. cr, uid, aj_cash_ids, ['name', 'id'], context=context)
  42. cash_res = [(r['id'], r['name']) for r in cash_res]
  43. aj_other_ids = aj_obj.search(
  44. cr, uid, [
  45. ('id', 'in', aj_ids), ('type', '!=', 'cash')
  46. ], context=context)
  47. other_res = aj_obj.read(
  48. cr, uid, aj_other_ids, ['name', 'id'], context=context)
  49. other_res = [(r['id'], r['name']) for r in other_res]
  50. return cash_res + other_res