test_event_internals.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from datetime import datetime, timedelta
  4. from odoo import Command
  5. from odoo.addons.event_booth_sale.tests.common import TestEventBoothSaleCommon
  6. from odoo.fields import Datetime as FieldsDatetime
  7. from odoo.tests.common import users, Form
  8. class TestEventData(TestEventBoothSaleCommon):
  9. @users('user_eventmanager')
  10. def test_event_configuration_booths_from_type(self):
  11. """ Test data computation (related to booths) of event coming from its event.type template. """
  12. # setup test records
  13. event_type_nobooth = self.env['event.type'].create({
  14. 'name': 'No booth',
  15. })
  16. event_type_wbooths = self.env['event.type'].create({
  17. 'name': 'Using booths',
  18. 'event_type_booth_ids': [
  19. Command.clear(),
  20. Command.create({
  21. 'name': 'Standard Booth',
  22. 'booth_category_id': self.event_booth_category_1.id,
  23. }),
  24. Command.create({
  25. 'name': 'Premium Booth',
  26. 'booth_category_id': self.event_booth_category_2.id,
  27. })
  28. ]
  29. })
  30. # no booth by default as no booths on type
  31. event = self.env['event.event'].create({
  32. 'name': 'Event',
  33. 'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)),
  34. 'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)),
  35. 'event_type_id': event_type_nobooth.id
  36. })
  37. self.assertEqual(event.event_booth_ids, self.env['event.booth'])
  38. # manually create booths: ok
  39. event.write({
  40. 'event_booth_ids': [
  41. Command.create({
  42. 'name': 'Custom Standard Booth 1',
  43. 'booth_category_id': self.event_booth_category_1.id,
  44. }),
  45. Command.create({
  46. 'name': 'Custom Standard Booth 2',
  47. 'booth_category_id': self.event_booth_category_1.id,
  48. })
  49. ]
  50. })
  51. self.assertEqual(event.event_booth_count, 2)
  52. self.assertEqual(event.event_booth_count_available, 2)
  53. self.assertEqual(event.event_booth_ids.product_id, self.event_booth_product)
  54. # updating partner is independent from availability
  55. event.event_booth_ids[1].write({'partner_id': self.event_customer.id})
  56. self.assertEqual(event.event_booth_count, 2)
  57. self.assertEqual(event.event_booth_count_available, 2)
  58. self.assertEqual(event.event_booth_ids[1].message_partner_ids, self.event_customer)
  59. # one booth is sold
  60. event.event_booth_ids[1].write({'state': 'unavailable'})
  61. self.assertEqual(event.event_booth_count, 2)
  62. self.assertEqual(event.event_booth_count_available, 1)
  63. # partner is reset: booth still unavailable but follower removed
  64. event.event_booth_ids[1].write({'partner_id': False})
  65. self.assertEqual(event.event_booth_count, 2)
  66. self.assertEqual(event.event_booth_count_available, 1)
  67. self.assertEqual(event.event_booth_ids[1].message_partner_ids, self.env['res.partner'])
  68. # add group or the test will fail
  69. self.user_eventmanager.write({'groups_id': [
  70. (4, self.env.ref('sales_team.group_sale_salesman').id),
  71. ]})
  72. # change event type to one using booths: include event type booths and keep reserved booths
  73. with Form(event) as event_form:
  74. event_form.event_type_id = event_type_wbooths
  75. self.assertEqual(event.event_booth_count, 3)
  76. self.assertEqual(
  77. set(r['name'] for r in event.event_booth_ids),
  78. set(('Custom Standard Booth 2', 'Standard Booth', 'Premium Booth')),
  79. 'Should keep booths with reservation, remove unused ones and add type ones'
  80. )
  81. self.assertEqual(event.event_booth_count_available, 2)
  82. self.assertEqual(event.event_booth_category_ids, self.event_booth_category_1 + self.event_booth_category_2)