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.

42 lines
1.4 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License MIT (https://opensource.org/licenses/MIT).
  3. from . import models
  4. from . import wizard
  5. from .tests import test_mail_model
  6. def post_init_hook(cr, registry):
  7. from odoo import api, SUPERUSER_ID
  8. env = api.Environment(cr, SUPERUSER_ID, {})
  9. env.cr.execute(
  10. "ALTER TABLE res_users ADD COLUMN IF NOT EXISTS email_multi_website VARCHAR"
  11. )
  12. # fill new email column with values from partner
  13. for user in env["res.users"].with_context(active_test=False).search([]):
  14. email = user.partner_id.email
  15. if email:
  16. user._force_default("email_multi_website", email)
  17. def uninstall_hook(cr, registry):
  18. from odoo import api, SUPERUSER_ID
  19. env = api.Environment(cr, SUPERUSER_ID, {})
  20. # remove properties
  21. field_ids = [
  22. env.ref("base.field_res_users_email").id,
  23. env.ref("base.field_res_users_signature").id,
  24. env.ref("mail.field_mail_template_body_html").id,
  25. env.ref("mail.field_mail_template_mail_server_id").id,
  26. env.ref("mail.field_mail_template_report_template").id,
  27. ]
  28. env["ir.property"].search([("fields_id", "in", field_ids)]).unlink()
  29. # copy emails from partner to user
  30. cr.execute("SELECT partner_id,email_multi_website FROM res_users")
  31. for partner_id, default_email in cr.fetchall():
  32. env["res.partner"].browse(partner_id).email = default_email