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.

105 lines
3.8 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. })
  15. self.pricelist = self.env['product.pricelist'].create({
  16. 'name': 'Test pricelist',
  17. 'item_ids': [(0, 0, {
  18. 'applied_on': '3_global',
  19. 'compute_price': 'formula',
  20. 'base': 'list_price',
  21. })]
  22. })
  23. # Create a new pos config and open it
  24. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
  25. self.pos_config.open_session_cb()
  26. def test_01_picking_delayed_enabled(self):
  27. # Enable feature
  28. self.pos_config.picking_creation_delayed = True
  29. order = self._create_order()
  30. self.assertEqual(
  31. order.picking_id.id, False,
  32. "Creating order via UI should not generate a picking if"
  33. " feature is enabled")
  34. # Test if a Queue Job has been generated
  35. func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id)
  36. queues = self.QueueJob.search([
  37. ('func_string', '=', func_string)])
  38. self.assertEqual(len(queues), 1, "Queue Job has not been created")
  39. def test_02_picking_delayed_disabled(self):
  40. # Disable feature
  41. self.pos_config.picking_creation_delayed = False
  42. order = self._create_order()
  43. picking_id = order.picking_id.id
  44. self.assertNotEqual(
  45. picking_id, False,
  46. "Creating order via UI should generate a picking if"
  47. " feature is disabled")
  48. # Test if a Queue Job has not been generated
  49. func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id)
  50. queues = self.QueueJob.search([
  51. ('func_string', '=', func_string)])
  52. self.assertEqual(len(queues), 0, "Queue Job has been created")
  53. def _create_order(self):
  54. # Create order
  55. order_data = {
  56. 'id': u'0006-001-0010',
  57. 'to_invoice': False,
  58. 'data': {
  59. 'pricelist_id': self.pricelist.id,
  60. 'user_id': 1,
  61. 'name': 'Order 0006-001-0010',
  62. 'partner_id': False,
  63. 'amount_paid': 0.9,
  64. 'pos_session_id': self.pos_config.current_session_id.id,
  65. 'lines': [[0, 0, {
  66. 'product_id': self.pos_product.id,
  67. 'price_unit': 0.9,
  68. 'qty': 1,
  69. 'price_subtotal': 0.9,
  70. 'price_subtotal_incl': 0.9,
  71. }]],
  72. 'statement_ids': [[0, 0, {
  73. 'journal_id': self.pos_config.journal_ids[0].id,
  74. 'amount': 0.9,
  75. 'name': fields.Datetime.now(),
  76. 'account_id':
  77. self.env.user.partner_id.property_account_receivable_id.id,
  78. 'statement_id':
  79. self.pos_config.current_session_id.statement_ids[0].id,
  80. }]],
  81. 'creation_date': u'2018-09-27 15:51:03',
  82. 'amount_tax': 0,
  83. 'fiscal_position_id': False,
  84. 'uid': u'00001-001-0001',
  85. 'amount_return': 0,
  86. 'sequence_number': 1,
  87. 'amount_total': 0.9,
  88. }}
  89. result = self.PosOrder.create_from_ui([order_data])
  90. order = self.PosOrder.browse(result[0])
  91. return order