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.

47 lines
1.5 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(
  15. string="Multi Website Email", related="email_multi_website", inherited=False
  16. )
  17. email_multi_website = fields.Char(company_dependent=True, website_dependent=True)
  18. @api.model
  19. def create(self, vals):
  20. res = super(User, self).create(vals)
  21. # make value company independent
  22. res._force_default(FIELD_NAME, vals.get("email"))
  23. for f in FIELDS:
  24. res._force_default(f, vals.get(f))
  25. return res
  26. @api.multi
  27. def write(self, vals):
  28. res = super(User, self).write(vals)
  29. # TODO: will it work with OCA's partner_firstname module?
  30. if any(k in vals for k in ["name", "email"] + FIELDS):
  31. for f in ALL_FIELDS:
  32. self._update_properties_label(f)
  33. return res
  34. def _auto_init(self):
  35. for f in FIELDS:
  36. self._auto_init_website_dependent(f)
  37. return super(User, self)._auto_init()