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.

34 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Tecnativa <https://www.tecnativa.com>
  3. # Copyright 2018 Eficent <http://www.eficent.com>
  4. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. def pre_init_hook(cr):
  8. """
  9. This pre-creates before ORM related computation the field `res_model`,
  10. for avoiding an error when writing back the value on virtual records
  11. created by recurring events. No need of writing any possible value, as
  12. this is a new feature not available in v10.
  13. See https://github.com/OCA/OpenUpgrade/blob/11.0/addons/calendar
  14. /migrations/11.0.1.0/pre-migration.py
  15. """
  16. _logger.info('Pre-creating column res_model in table calendar_event')
  17. cr.execute("""SELECT column_name
  18. FROM information_schema.columns
  19. WHERE table_name='calendar_event' AND
  20. column_name='res_model'""")
  21. if not cr.fetchone():
  22. cr.execute(
  23. """
  24. ALTER TABLE calendar_event
  25. ADD COLUMN res_model
  26. character varying;
  27. COMMENT ON COLUMN calendar_event.res_model
  28. IS 'Document Model Name';
  29. """)