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.

106 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import fields
  5. from odoo.tests.common import TransactionCase
  6. class TestModule(TransactionCase):
  7. def setUp(self):
  8. super(TestModule, self).setUp()
  9. self.pos_order_obj = self.env['pos.order']
  10. self.pos_picking_cron = self.env.ref(
  11. 'pos_picking_delayed.cron_create_delayed_pos_picking')
  12. self.pos_config = self.env.ref('point_of_sale.pos_config_main')
  13. self.carotte_product = self.env.ref('point_of_sale.carotte')
  14. def test_01_picking_delayed_enabled(self):
  15. # Disable Cron
  16. self.pos_picking_cron.active = False
  17. # Enable feature
  18. self.pos_config.picking_creation_delayed = True
  19. order = self._open_session_create_order()
  20. self.assertEqual(
  21. order.picking_id.id, False,
  22. "Creating order via UI should not generate a picking if"
  23. " feature is enabled")
  24. # run cron and test if picking is now created
  25. self.pos_picking_cron.method_direct_trigger()
  26. self.assertNotEqual(
  27. order.picking_id.id, False,
  28. "Run PoS picking Cron should generate picking for PoS Orders"
  29. " without picking")
  30. def test_02_picking_delayed_disabled(self):
  31. # Disable Cron
  32. self.pos_picking_cron.active = False
  33. # Disable feature
  34. self.pos_config.picking_creation_delayed = False
  35. order = self._open_session_create_order()
  36. picking_id = order.picking_id.id
  37. self.assertNotEqual(
  38. picking_id, False,
  39. "Creating order via UI should generate a picking if"
  40. " feature is disabled")
  41. # run cron and test if picking is now created
  42. self.pos_picking_cron.method_direct_trigger()
  43. self.assertEqual(
  44. order.picking_id.id, picking_id,
  45. "Run PoS picking Cron should not regenerate picking for"
  46. " PoS Orders that have already a picking created.")
  47. def _open_session_create_order(self):
  48. # Create order
  49. self.pos_config.open_session_cb()
  50. order_data = {
  51. 'id': u'0006-001-0010',
  52. 'to_invoice': False,
  53. 'data': {
  54. 'user_id': 1,
  55. 'name': 'Order 0006-001-0010',
  56. 'partner_id': False,
  57. 'amount_paid': 0.9,
  58. 'pos_session_id': self.pos_config.current_session_id.id,
  59. 'lines': [[0, 0, {
  60. 'id': 1,
  61. 'product_id': self.carotte_product.id,
  62. 'tax_ids': [[6, False, []]],
  63. 'price_unit': 0.9,
  64. 'qty': 1,
  65. 'pack_lot_ids': [],
  66. 'discount': 0,
  67. }]],
  68. 'statement_ids': [[0, 0, {
  69. 'journal_id': self.pos_config.journal_ids[0].id,
  70. 'amount': 0.9,
  71. 'name': fields.Datetime.now(),
  72. 'account_id':
  73. self.env.user.partner_id.property_account_receivable_id.id,
  74. 'statement_id':
  75. self.pos_config.current_session_id.statement_ids[0].id,
  76. }]],
  77. 'creation_date': u'2018-09-27 15:51:03',
  78. 'amount_tax': 0,
  79. 'fiscal_position_id': False,
  80. 'uid': u'00001-001-0001',
  81. 'amount_return': 0,
  82. 'sequence_number': 1,
  83. 'amount_total': 0.9,
  84. }}
  85. # Test if picking is not created
  86. result = self.pos_order_obj.create_from_ui([order_data])
  87. order = self.pos_order_obj.browse(result[0])
  88. return order