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.

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