OCA reporting engine fork for dev and update.
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.

57 lines
1.7 KiB

  1. from odoo import tools
  2. import logging
  3. _logger = logging.getLogger(__name__)
  4. def migrate(cr, version):
  5. _logger.debug('Migrating res.partner comment_template_id')
  6. if not tools.column_exists(cr, 'res_partner', 'comment_template_id'):
  7. return
  8. cr.execute("SELECT id FROM res_company")
  9. company_ids = [d[0] for d in cr.fetchall()]
  10. cr.execute(
  11. "SELECT id FROM ir_model_fields WHERE model=%s AND name=%s",
  12. ('res.partner', 'property_comment_template_id'))
  13. [field_id] = cr.fetchone()
  14. for company_id in company_ids:
  15. cr.execute("""
  16. INSERT INTO ir_property(
  17. name,
  18. type,
  19. fields_id,
  20. company_id,
  21. res_id,
  22. value_reference
  23. )
  24. SELECT
  25. {field},
  26. 'many2one',
  27. {field_id},
  28. {company_id},
  29. CONCAT('{model},',id),
  30. CONCAT('{target_model},',{oldfield})
  31. FROM {table} t
  32. WHERE {oldfield} IS NOT NULL
  33. AND (company_id IS NULL OR company_id = {company_id})
  34. AND NOT EXISTS(
  35. SELECT 1
  36. FROM ir_property
  37. WHERE fields_id={field_id}
  38. AND company_id={company_id}
  39. AND res_id=CONCAT('{model},',t.id)
  40. )
  41. """.format(
  42. oldfield='comment_template_id',
  43. field='property_comment_template_id',
  44. field_id=field_id,
  45. company_id=company_id,
  46. model='res.partner',
  47. target_model='base.comment.template',
  48. table='res_partner',
  49. ))