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.

162 lines
6.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import fields
  5. from odoo.tests.common import SavepointCase
  6. class TestSequenceNumberSync(SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. """
  10. Simulation of sales coming from the interface
  11. """
  12. super(TestSequenceNumberSync, cls).setUpClass()
  13. # ENVIRONEMENTS
  14. cls.pos_obj = cls.env['pos.order']
  15. cls.partner_obj = cls.env['res.partner']
  16. # INSTANCES
  17. cls.partner = cls.partner_obj.create({'name': 'test_partner_A'})
  18. cls.product = cls.env.ref(
  19. 'product.product_order_01')
  20. cls.pos_config = cls.env.ref('point_of_sale.pos_config_main')
  21. # USING VARIABLE
  22. cls.sequence_ref_number = 10
  23. cls.sequence_number = 2
  24. # USER PARTNER
  25. cls.user_partner = cls.env.user.partner_id
  26. def get_data(self, session, sequence_number):
  27. return '000' + str(session.id) + '-001-000' + str(sequence_number)
  28. def ui_order_data(self, sequence_ref_number, sequence_number,
  29. current_session):
  30. values = {
  31. 'data': {
  32. 'creation_date': fields.Datetime.now(),
  33. 'fiscal_position_id': False,
  34. 'pricelist_id': current_session.config_id.pricelist_id.id,
  35. 'amount_return': 0,
  36. 'sequence_ref_number': sequence_ref_number,
  37. 'lines': [[0, 0, {'product_id': self.product.id,
  38. 'qty': 1}]],
  39. 'name': 'Order ' + self.get_data(
  40. current_session, sequence_number),
  41. 'partner_id': False,
  42. 'pos_session_id': current_session.id,
  43. 'sequence_number': sequence_number,
  44. 'statement_ids': [[0, 0, {
  45. 'account_id':
  46. self.user_partner.property_account_receivable_id.id,
  47. 'amount': 0.9,
  48. 'journal_id': self.pos_config.journal_ids[0].id,
  49. 'name': fields.Datetime.now(),
  50. 'statement_id':current_session.statement_ids[0].id}]],
  51. 'user_id': self.env.uid
  52. },
  53. 'to_invoice': False
  54. }
  55. # because travis install (pos_loyalty)
  56. # may be an edge effect
  57. if 'loyalty_points' in self.pos_obj._fields:
  58. values['data']['loyalty_points'] = 0
  59. return values
  60. def test_check_sequence_number_sync_00(self):
  61. """
  62. case 1 :
  63. 1 - create order from ui
  64. 2 - close session
  65. 3 - create new order from ui,
  66. 4 - close session
  67. 5 - validate closing & post entries
  68. sequence result : 000session_id-001-000sequence_number
  69. and 000new_session_id+1-001-000sequence_number
  70. order name result : Main/00sequence_ref_number
  71. """
  72. # click on create a new session button
  73. self.pos_config.open_session_cb()
  74. # session
  75. current_session = self.pos_config.current_session_id
  76. # data
  77. ui_order = self.ui_order_data(self.sequence_ref_number,
  78. self.sequence_number, current_session)
  79. # I create an order on an open session
  80. pos_order_id = self.pos_obj.create_from_ui([ui_order])
  81. pos_order = self.env['pos.order'].browse(pos_order_id)
  82. self.assertEqual(pos_order.name,
  83. 'Main/00' + str(self.sequence_ref_number))
  84. self.assertEqual(pos_order.pos_reference,
  85. 'Order 000' + str(current_session.id)+'-001-0002')
  86. # close the session
  87. self.pos_config.current_session_id.action_pos_session_closing_control()
  88. # create an open new session
  89. self.pos_config.open_session_cb()
  90. new_current_session = self.pos_config.current_session_id
  91. ui_order['data']['pos_session_id'] = new_current_session.id
  92. ui_order['data']['name'] = self.get_data(
  93. new_current_session, self.sequence_number)
  94. # create an order on an open session
  95. pos_order_id = self.pos_obj.create_from_ui([ui_order])
  96. pos_order = self.env['pos.order'].browse(pos_order_id)
  97. self.assertEqual(pos_order.name,
  98. 'Main/00' + str(self.sequence_ref_number))
  99. self.assertEqual(pos_order.pos_reference,
  100. '000' + str(new_current_session.id)+'-001-0002')
  101. def test_check_sequence_number_sync_01(self):
  102. """
  103. case 2 :
  104. 1 - create order from ui,
  105. 2 - create new order from ui
  106. 3 - validate closing & post entries
  107. sequence result : 000session_id-001-000sequence_number
  108. and 000session_id-001-000new_sequence_number
  109. order name result : Main/00sequence_ref_number
  110. """
  111. # create a new session button
  112. self.pos_config.open_session_cb()
  113. # session
  114. current_session = self.pos_config.current_session_id
  115. # data
  116. ui_order = self.ui_order_data(self.sequence_ref_number,
  117. self.sequence_number, current_session)
  118. # create an order on an open session
  119. pos_order_id = self.pos_obj.create_from_ui([ui_order])
  120. pos_order = self.env['pos.order'].browse(pos_order_id)
  121. self.assertEqual(pos_order.name,
  122. 'Main/00' + str(self.sequence_ref_number))
  123. self.assertEqual(pos_order.pos_reference,
  124. 'Order 000' + str(current_session.id) + '-001-0002')
  125. self.sequence_number = self.sequence_number+1
  126. ui_order = self.ui_order_data(self.sequence_ref_number,
  127. self.sequence_number, current_session)
  128. pos_order_id = self.pos_obj.create_from_ui([ui_order])
  129. pos_order = self.env['pos.order'].browse(pos_order_id)
  130. self.assertEqual(pos_order.name,
  131. 'Main/00' + str(self.sequence_ref_number))
  132. self.assertEqual(pos_order.pos_reference,
  133. 'Order 000' + str(current_session.id) + '-001-0003')
  134. # close the session
  135. self.pos_config.current_session_id.action_pos_session_closing_control()