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.

40 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("ALTER TABLE res_users ADD COLUMN email_multi_website VARCHAR")
  10. # fill new email column with values from partner
  11. for user in env["res.users"].with_context(active_test=False).search([]):
  12. email = user.partner_id.email
  13. if email:
  14. user._force_default("email_multi_website", email)
  15. def uninstall_hook(cr, registry):
  16. from odoo import api, SUPERUSER_ID
  17. env = api.Environment(cr, SUPERUSER_ID, {})
  18. # remove properties
  19. field_ids = [
  20. env.ref("base.field_res_users_email").id,
  21. env.ref("base.field_res_users_signature").id,
  22. env.ref("mail.field_mail_template_body_html").id,
  23. env.ref("mail.field_mail_template_mail_server_id").id,
  24. env.ref("mail.field_mail_template_report_template").id,
  25. ]
  26. env["ir.property"].search([("fields_id", "in", field_ids)]).unlink()
  27. # copy emails from partner to user
  28. cr.execute("SELECT partner_id,email_multi_website FROM res_users")
  29. for partner_id, default_email in cr.fetchall():
  30. env["res.partner"].browse(partner_id).email = default_email