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.

95 lines
3.5 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Store Draft Orders Module for Odoo
  5. # Copyright (C) 2015-Today 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.exceptions import Warning
  23. from openerp.tests.common import TransactionCase
  24. class TestPosStoreDraftOrder(TransactionCase):
  25. def setUp(self):
  26. super(TestPosStoreDraftOrder, self).setUp()
  27. self.session_obj = self.env['pos.session']
  28. self.order_obj = self.env['pos.order']
  29. self.pos_config_id = self.ref('point_of_sale.pos_config_main')
  30. self.product_id = self.ref('product.product_product_48')
  31. self.cash_journal_id = self.ref('account.cash_journal')
  32. # Test Section
  33. def test_01_allow_draft_order_unpaid(self):
  34. """Test the possibility to let a PoS Order in a draft state if it is
  35. not paid at all."""
  36. # Open a new session
  37. session_1 = self.session_obj.create({'config_id': self.pos_config_id})
  38. # Create Order
  39. order = self.order_obj.create({
  40. 'session_id': session_1.id,
  41. 'lines': [[0, False, {
  42. 'discount': 0,
  43. 'price_unit': 10,
  44. 'product_id': self.product_id,
  45. 'qty': 1}]]
  46. })
  47. # Close Session
  48. session_1.signal_workflow('close')
  49. self.assertEquals(
  50. session_1.state, 'closed',
  51. "Unpaid Draft Orders must not block the closing process of the"
  52. " associated session.")
  53. # Open a second session
  54. session_2 = self.session_obj.create({'config_id': self.pos_config_id})
  55. self.assertEquals(
  56. order.session_id.id, session_2.id,
  57. "Draft Orders of a previous session must be associated to the"
  58. " new opened session to allow payment.")
  59. # Test Section
  60. def test_02_block_draft_order_partial_paid(self):
  61. """Test the unpossibility to let a PoS Order in a draft state if it is
  62. in a partial paid state."""
  63. # Open a new session
  64. session_1 = self.session_obj.create({'config_id': self.pos_config_id})
  65. # Create Order
  66. order = self.order_obj.create({
  67. 'session_id': session_1.id,
  68. 'lines': [[0, False, {
  69. 'discount': 0,
  70. 'price_unit': 10,
  71. 'product_id': self.product_id,
  72. 'qty': 3}]]
  73. })
  74. # Make partial payment
  75. self.order_obj.add_payment(
  76. order.id, {'amount': 1, 'journal': self.cash_journal_id})
  77. # Try Close Session (Must fail)
  78. with self.assertRaises(Warning):
  79. session_1.signal_workflow('close')