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.

45 lines
1.4 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License MIT (https://opensource.org/licenses/MIT).
  3. import logging
  4. from odoo import api, fields, models
  5. _logger = logging.getLogger(__name__)
  6. FIELD_NAME = "email_multi_website"
  7. FIELDS = ["signature"]
  8. ALL_FIELDS = [FIELD_NAME] + FIELDS
  9. class User(models.Model):
  10. _inherit = ["res.users", "website_dependent.mixin"]
  11. _name = "res.users"
  12. signature = fields.Html(company_dependent=True, website_dependent=True)
  13. # extra field to detach email field from res.partner
  14. email = fields.Char(related="email_multi_website", inherited=False)
  15. email_multi_website = fields.Char(company_dependent=True, website_dependent=True)
  16. @api.model
  17. def create(self, vals):
  18. res = super(User, self).create(vals)
  19. # make value company independent
  20. res._force_default(FIELD_NAME, vals.get("email"))
  21. for f in FIELDS:
  22. res._force_default(f, vals.get(f))
  23. return res
  24. @api.multi
  25. def write(self, vals):
  26. res = super(User, self).write(vals)
  27. # TODO: will it work with OCA's partner_firstname module?
  28. if any(k in vals for k in ["name", "email"] + FIELDS):
  29. for f in ALL_FIELDS:
  30. self._update_properties_label(f)
  31. return res
  32. def _auto_init(self):
  33. for f in FIELDS:
  34. self._auto_init_website_dependent(f)
  35. return super(User, self)._auto_init()