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.

170 lines
6.4 KiB

  1. # Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests.common import TransactionCase
  5. from odoo.exceptions import ValidationError
  6. from odoo.exceptions import Warning as UserError
  7. class TestMultipleControl(TransactionCase):
  8. """Tests for 'Point of Sale - Multiple Control' Module"""
  9. def setUp(self):
  10. super(TestMultipleControl, self).setUp()
  11. self.session_obj = self.env["pos.session"]
  12. self.order_obj = self.env["pos.order"]
  13. self.payment_obj = self.env["pos.make.payment"]
  14. self.partner = self.env.ref("base.partner_demo_portal")
  15. self.product = self.env.ref("product.product_product_3")
  16. self.pos_move_reason = self.env.ref(
  17. "pos_multiple_control.cash_register_error"
  18. )
  19. self.pos_config = self.env.ref(
  20. "pos_multiple_control.pos_config_control"
  21. )
  22. self.check_journal = self.env.ref("pos_multiple_control.check_journal")
  23. self.cash_journal = self.env.ref("pos_multiple_control.cash_journal")
  24. def _order(self, session, price, journal):
  25. # I create a new PoS order with 2 lines
  26. order = self.order_obj.create({
  27. 'session_id': session.id,
  28. 'partner_id': self.partner.id,
  29. 'pricelist_id': self.partner.property_product_pricelist.id,
  30. 'lines': [(0, 0, {
  31. 'name': "OL/0001",
  32. 'product_id': self.product.id,
  33. 'price_unit': price,
  34. 'qty': 1.0,
  35. # 'tax_ids': [(6, 0, self.product.taxes_id.ids)],
  36. 'price_subtotal': price,
  37. 'price_subtotal_incl': price,
  38. })],
  39. 'amount_total': price,
  40. 'amount_tax': 0.0,
  41. 'amount_paid': 0.0,
  42. 'amount_return': 0.0,
  43. })
  44. return order
  45. def _order_and_pay(self, session, price, journal):
  46. order = self._order(session, price, journal)
  47. context_make_payment = {
  48. "active_ids": [order.id],
  49. "active_id": order.id
  50. }
  51. self.pos_make_payment = self.payment_obj.with_context(
  52. context_make_payment).create({'amount': price})
  53. # I click on the validate button to register the payment.
  54. context_payment = {'active_id': order.id}
  55. self.pos_make_payment.with_context(context_payment).check()
  56. return order
  57. # Test Section
  58. def test_01_two_opening_session(self):
  59. # I create new session
  60. self.session_obj.create({"config_id": self.pos_config.id})
  61. # I Try to create a new session
  62. with self.assertRaises(ValidationError):
  63. self.session_obj.create({"config_id": self.pos_config.id})
  64. def test_02_opening_and_opened_session(self):
  65. # I create new session and open it
  66. session = self.session_obj.create({"config_id": self.pos_config.id})
  67. self.pos_config.open_session_cb()
  68. self.pos_config._open_session(session.id)
  69. # I Try to create a new session
  70. with self.assertRaises(ValidationError):
  71. self.session_obj.create({"config_id": self.pos_config.id})
  72. def test_03_check_close_session_with_draft_order(self):
  73. # I create new session and open it
  74. session = self.session_obj.create({"config_id": self.pos_config.id})
  75. self.pos_config.open_session_cb()
  76. self.pos_config._open_session(session.id)
  77. # Create a Draft order, and try to close the session
  78. self._order(session, 1, self.check_journal)
  79. with self.assertRaises(UserError):
  80. session.wkf_action_closing_control()
  81. def test_04_check_bank_statement_control(self):
  82. # I create new session and open it
  83. session = self.session_obj.create({"config_id": self.pos_config.id})
  84. # Make 2 Sales of 1100 and check transactions and theoritical balance
  85. self.pos_config.open_session_cb()
  86. self.pos_config._open_session(session.id)
  87. self._order_and_pay(session, 100, self.check_journal)
  88. self._order_and_pay(session, 1000, self.check_journal)
  89. self.assertEqual(
  90. session.control_register_total_entry_encoding,
  91. 1100,
  92. "Incorrect transactions total",
  93. )
  94. self.assertEqual(
  95. session.control_register_balance_end,
  96. session.control_register_balance_start + 1100,
  97. "Incorrect theoritical ending balance",
  98. )
  99. with self.assertRaises(UserError):
  100. session.action_pos_session_validate()
  101. def test_05_check_autosolve(self):
  102. # I create new session and open it
  103. self.pos_config.write(
  104. {
  105. "autosolve_pos_move_reason": self.pos_move_reason.id,
  106. "autosolve_limit": 20,
  107. }
  108. )
  109. session = self.session_obj.create({"config_id": self.pos_config.id})
  110. # Make sales and autosolve
  111. self.pos_config.open_session_cb()
  112. self.pos_config._open_session(session.id)
  113. sale = self._order_and_pay(session, 18, self.check_journal)
  114. sale.statement_ids[0].statement_id.automatic_solve()
  115. self.assertEqual(
  116. session.summary_statement_ids[1].control_difference,
  117. 0,
  118. "Incorrect transactions total",
  119. )
  120. def test_06_check_display_button(self):
  121. # I create new session and open it
  122. self.pos_config.write(
  123. {
  124. "autosolve_pos_move_reason": self.pos_move_reason.id,
  125. "autosolve_limit": 30,
  126. }
  127. )
  128. session = self.session_obj.create({"config_id": self.pos_config.id})
  129. # Make sales too important
  130. self.pos_config.open_session_cb()
  131. self.pos_config._open_session(session.id)
  132. sale = self._order_and_pay(session, 31, self.check_journal)
  133. self.assertEqual(
  134. sale.statement_ids[0].statement_id.display_autosolve,
  135. False,
  136. "Autosolve button should be hidden",
  137. )
  138. # Autosolve and second sales
  139. sale.statement_ids[0].statement_id.automatic_solve()
  140. sale2 = self._order_and_pay(session, 29, self.check_journal)
  141. sale2.statement_ids[0].statement_id._compute_display_autosolve()
  142. self.assertEqual(
  143. sale2.statement_ids[0].statement_id.display_autosolve,
  144. True,
  145. "Autosolve button should not be hidden",
  146. )