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.

65 lines
2.8 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # POS Keep Draft Orders module for Odoo
  5. # Copyright (C) 2013-2014 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 osv.osv import except_osv
  24. from openerp.osv.orm import Model
  25. from openerp.tools.translate import _
  26. class pos_session(Model):
  27. _inherit = 'pos.session'
  28. # Overload Section
  29. def wkf_action_closing_control(self, cr, uid, ids, context=None):
  30. """Remove all PoS Orders in 'draft' to the sessions we want
  31. to close.
  32. Check if there is Partial Paid Orders"""
  33. po_obj = self.pool['pos.order']
  34. for ps in self.browse(cr, uid, ids, context=context):
  35. for po in ps.order_ids:
  36. # Check if there is a partial payment
  37. if po.is_partial_paid:
  38. raise except_osv(
  39. _('Error!'),
  40. _("You cannot confirm this session, because '%s'"
  41. " is in a 'draft' state with payments.\n\n"
  42. "Please finish to pay this Order." % (
  43. po.name)))
  44. # remove session id on the current PoS if it is in draft mode
  45. if po.state == 'draft' and ps.config_id.allow_slate:
  46. po_obj.write(cr, uid, po.id, {
  47. 'session_id': None}, context=context)
  48. return super(pos_session, self).wkf_action_closing_control(
  49. cr, uid, ids, context=context)
  50. def create(self, cr, uid, values, context=None):
  51. """Recover all PoS Order in 'draft' mode and associate them to the new
  52. Pos Session"""
  53. po_obj = self.pool['pos.order']
  54. ps_id = super(pos_session, self).create(cr, uid, values, context)
  55. po_ids = po_obj.search(cr, uid, [
  56. ('state', '=', 'draft'), ('user_id', '=', uid)],
  57. context=context)
  58. po_obj.write(
  59. cr, uid, po_ids, {'session_id': ps_id}, context=context)
  60. return ps_id