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.

46 lines
1.5 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  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. def write(self, vals):
  27. res = super(User, self).write(vals)
  28. # TODO: will it work with OCA's partner_firstname module?
  29. if any(k in vals for k in ["name", "email"] + FIELDS):
  30. for f in ALL_FIELDS:
  31. self._update_properties_label(f)
  32. return res
  33. def _auto_init(self):
  34. for f in FIELDS:
  35. self._auto_init_website_dependent(f)
  36. return super(User, self)._auto_init()