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.

104 lines
4.1 KiB

  1. # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import fields
  4. from odoo.tests.common import TransactionCase
  5. class TestModule(TransactionCase):
  6. def setUp(self):
  7. super(TestModule, self).setUp()
  8. self.PosOrder = self.env['pos.order']
  9. self.QueueJob = self.env['queue.job']
  10. self.pos_product = self.env['product.product'].create({
  11. 'name': 'Test POS product',
  12. 'type': 'product',
  13. 'available_in_pos': True,
  14. 'taxes_id': False,
  15. })
  16. self.pricelist = self.env['product.pricelist'].create({
  17. 'name': 'Test pricelist',
  18. 'item_ids': [(0, 0, {
  19. 'applied_on': '3_global',
  20. 'compute_price': 'formula',
  21. 'base': 'list_price',
  22. })]
  23. })
  24. pos_config_main = self.env.ref('point_of_sale.pos_config_main')
  25. # Ensure tests correctness despite default currency
  26. pos_config_main.write({
  27. 'available_pricelist_ids': [(6, 0, self.pricelist.ids)],
  28. 'pricelist_id': self.pricelist.id,
  29. })
  30. self.pos_config = pos_config_main.copy()
  31. self.pos_config.open_session_cb()
  32. def test_01_picking_delayed_enabled(self):
  33. # Enable feature
  34. self.pos_config.picking_creation_delayed = True
  35. order = self._create_order()
  36. self.assertEqual(
  37. order.picking_id.id, False,
  38. "Creating order via UI should not generate a picking if"
  39. " feature is enabled")
  40. # Test if a Queue Job has been generated
  41. func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id)
  42. queues = self.QueueJob.search([
  43. ('func_string', '=', func_string)])
  44. self.assertEqual(len(queues), 1, "Queue Job has not been created")
  45. def test_02_picking_delayed_disabled(self):
  46. # Disable feature
  47. self.pos_config.picking_creation_delayed = False
  48. order = self._create_order()
  49. picking_id = order.picking_id.id
  50. self.assertNotEqual(
  51. picking_id, False,
  52. "Creating order via UI should generate a picking if"
  53. " feature is disabled")
  54. # Test if a Queue Job has not been generated
  55. func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id)
  56. queues = self.QueueJob.search([
  57. ('func_string', '=', func_string)])
  58. self.assertEqual(len(queues), 0, "Queue Job has been created")
  59. def _create_order(self):
  60. # Create order
  61. order_data = {
  62. 'id': '0006-001-0010',
  63. 'to_invoice': False,
  64. 'data': {
  65. 'pricelist_id': self.pricelist.id,
  66. 'user_id': 1,
  67. 'name': 'Order 0006-001-0010',
  68. 'partner_id': False,
  69. 'amount_paid': 0.9,
  70. 'pos_session_id': self.pos_config.current_session_id.id,
  71. 'lines': [[0, 0, {
  72. 'product_id': self.pos_product.id,
  73. 'price_unit': 0.9,
  74. 'qty': 1,
  75. 'price_subtotal': 0.9,
  76. 'price_subtotal_incl': 0.9,
  77. }]],
  78. 'statement_ids': [[0, 0, {
  79. 'journal_id': self.pos_config.journal_ids[0].id,
  80. 'amount': 0.9,
  81. 'name': fields.Datetime.now(),
  82. 'account_id':
  83. self.env.user.partner_id.property_account_receivable_id.id,
  84. 'statement_id':
  85. self.pos_config.current_session_id.statement_ids[0].id,
  86. }]],
  87. 'creation_date': '2018-09-27 15:51:03',
  88. 'amount_tax': 0,
  89. 'fiscal_position_id': False,
  90. 'uid': '00001-001-0001',
  91. 'amount_return': 0,
  92. 'sequence_number': 1,
  93. 'amount_total': 0.9,
  94. }}
  95. result = self.PosOrder.create_from_ui([order_data])
  96. order = self.PosOrder.browse(result[0])
  97. return order