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