test_event_internals.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from datetime import date, datetime, timedelta
  4. from freezegun import freeze_time
  5. from odoo.addons.event_sale.tests.common import TestEventSaleCommon
  6. from odoo.fields import Datetime as FieldsDatetime, Date as FieldsDate
  7. from odoo.tests.common import users
  8. class TestEventData(TestEventSaleCommon):
  9. @users('user_eventmanager')
  10. def test_event_configuration_from_type(self):
  11. """ In addition to event test, also test tickets configuration coming
  12. from event_sale capabilities. """
  13. event_type = self.event_type_tickets.with_user(self.env.user)
  14. self.assertEqual(event_type.event_type_ticket_ids.description, self.event_product.description_sale)
  15. event = self.env['event.event'].create({
  16. 'name': 'Event Update Type',
  17. 'event_type_id': event_type.id,
  18. 'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)),
  19. 'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)),
  20. })
  21. # synchronize event
  22. event.write({'event_type_id': event_type.id})
  23. self.assertEqual(event.event_ticket_ids.name, event.event_type_id.event_type_ticket_ids.name)
  24. self.assertTrue(event.event_ticket_ids.seats_limited)
  25. self.assertEqual(event.event_ticket_ids.seats_max, 5)
  26. self.assertEqual(event.event_ticket_ids.product_id, self.event_product)
  27. self.assertEqual(event.event_ticket_ids.price, self.event_product.list_price)
  28. self.assertEqual(event.event_ticket_ids.description, self.event_product.description_sale)
  29. def test_event_registrable(self):
  30. """Test if `_compute_event_registrations_open` works properly with additional
  31. product active conditions compared to base tests (see event) """
  32. event = self.event_0.with_user(self.env.user)
  33. self.assertTrue(event.event_registrations_open)
  34. # ticket without dates boundaries -> ok
  35. ticket = self.env['event.event.ticket'].create({
  36. 'name': 'TestTicket',
  37. 'event_id': event.id,
  38. 'product_id': self.event_product.id,
  39. })
  40. self.assertTrue(event.event_registrations_open)
  41. # ticket has inactive product -> ko
  42. ticket.product_id.action_archive()
  43. self.assertFalse(event.event_registrations_open)
  44. # at least one valid ticket -> ok is back
  45. event_product = self.env['product.product'].create({'name': 'Test Registration Product New',})
  46. new_ticket = self.env['event.event.ticket'].create({
  47. 'name': 'TestTicket 2',
  48. 'event_id': event.id,
  49. 'product_id': event_product.id,
  50. 'end_sale_datetime': FieldsDatetime.to_string(datetime.now() + timedelta(days=2)),
  51. })
  52. self.assertTrue(new_ticket.sale_available)
  53. self.assertTrue(event.event_registrations_open)
  54. class TestEventTicketData(TestEventSaleCommon):
  55. @freeze_time('2020-01-31 10:00:00')
  56. @users('user_eventmanager')
  57. def test_event_ticket_fields(self):
  58. """ Test event ticket fields synchronization """
  59. event = self.event_0.with_user(self.env.user)
  60. event.write({
  61. 'event_ticket_ids': [
  62. (5, 0),
  63. (0, 0, {
  64. 'name': 'First Ticket',
  65. 'product_id': self.event_product.id,
  66. 'seats_max': 30,
  67. }), (0, 0, { # limited in time, available (01/10 (start) < 01/31 (today) < 02/10 (end))
  68. 'name': 'Second Ticket',
  69. 'product_id': self.event_product.id,
  70. 'start_sale_datetime': datetime(2020, 1, 10, 0, 0, 0),
  71. 'end_sale_datetime': datetime(2020, 2, 10, 23, 59, 59),
  72. })
  73. ],
  74. })
  75. first_ticket = event.event_ticket_ids.filtered(lambda t: t.name == 'First Ticket')
  76. second_ticket = event.event_ticket_ids.filtered(lambda t: t.name == 'Second Ticket')
  77. # force second ticket price, after calling the onchange
  78. second_ticket.write({'price': 8.0})
  79. # price coming from product
  80. self.assertEqual(first_ticket.price, self.event_product.list_price)
  81. self.assertEqual(second_ticket.price, 8.0)
  82. # default availability
  83. self.assertTrue(first_ticket.seats_limited)
  84. self.assertTrue(first_ticket.sale_available)
  85. self.assertFalse(first_ticket.is_expired)
  86. self.assertFalse(second_ticket.seats_limited)
  87. self.assertTrue(second_ticket.sale_available)
  88. self.assertFalse(second_ticket.is_expired)
  89. # product archived
  90. self.event_product.action_archive()
  91. self.assertFalse(first_ticket.sale_available)
  92. self.assertFalse(second_ticket.sale_available)
  93. # sale is ended
  94. self.event_product.action_unarchive()
  95. second_ticket.write({'end_sale_datetime': datetime(2020, 1, 20, 23, 59, 59)})
  96. self.assertFalse(second_ticket.sale_available)
  97. self.assertTrue(second_ticket.is_expired)
  98. # sale has not started
  99. second_ticket.write({
  100. 'start_sale_datetime': datetime(2020, 2, 10, 0, 0, 0),
  101. 'end_sale_datetime': datetime(2020, 2, 20, 23, 59, 59),
  102. })
  103. self.assertFalse(second_ticket.sale_available)
  104. self.assertFalse(second_ticket.is_expired)