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.

36 lines
1.2 KiB

  1. # Copyright 2020 Camptocamp SA
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
  3. import logging
  4. _logger = logging.getLogger(__name__)
  5. def pre_init_hook(cr):
  6. """Create column using SQL to avoid auto-init updating the table row by row
  7. :param odoo.sql_db.Cursor cr:
  8. Database cursor.
  9. """
  10. _logger.info("Creating res.company.partner_ref_unique column")
  11. cr.execute("ALTER TABLE res_company ADD partner_ref_unique varchar NULL;")
  12. cr.execute(
  13. "COMMENT ON COLUMN public.res_company.partner_ref_unique "
  14. "IS 'Unique partner reference for';"
  15. )
  16. cr.execute(
  17. "UPDATE res_company SET partner_ref_unique = 'none';"
  18. )
  19. _logger.info(
  20. "Creating res.partner.partner_ref_unique column with value from "
  21. "res.company"
  22. )
  23. cr.execute("ALTER TABLE res_partner ADD partner_ref_unique varchar NULL;")
  24. cr.execute(
  25. "COMMENT ON COLUMN res_partner.partner_ref_unique "
  26. "IS 'Unique partner reference for';"
  27. )
  28. cr.execute(
  29. "UPDATE res_partner rp "
  30. "SET partner_ref_unique = rc.partner_ref_unique "
  31. "FROM res_company rc "
  32. "WHERE rc.id = rp.company_id;"
  33. )