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.

49 lines
1.7 KiB

6 years ago
6 years ago
  1. # Copyright 2013 Nicolas Bessi (Camptocamp SA)
  2. # Copyright 2014 Agile Business Group (<http://www.agilebg.com>)
  3. # Copyright 2015 Grupo ESOC (<http://www.grupoesoc.es>)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import _, api, models
  6. class ResUser(models.Model):
  7. _inherit = "res.users"
  8. @api.model
  9. def default_get(self, fields_list):
  10. """Invert name when getting default values."""
  11. result = super(ResUser, self).default_get(fields_list)
  12. partner_model = self.env["res.partner"]
  13. inverted = partner_model._get_inverse_name(
  14. partner_model._get_whitespace_cleaned_name(result.get("name", "")),
  15. result.get("is_company", False),
  16. )
  17. for field in list(inverted.keys()):
  18. if field in fields_list:
  19. result[field] = inverted.get(field)
  20. return result
  21. @api.onchange("firstname", "lastname")
  22. def _compute_name(self):
  23. """Write the 'name' field according to splitted data."""
  24. for rec in self:
  25. rec.name = rec.partner_id._get_computed_name(rec.lastname, rec.firstname)
  26. def copy(self, default=None):
  27. self.ensure_one()
  28. default = dict(default or {})
  29. if ("name" not in default) and ("partner_id" not in default):
  30. default["name"] = _("%s (copy)") % self.name
  31. if "login" not in default:
  32. default["login"] = _("%s (copy)") % self.login
  33. if (
  34. ("firstname" not in default)
  35. and ("lastname" not in default)
  36. and ("name" in default)
  37. ):
  38. default.update(
  39. self.env["res.partner"]._get_inverse_name(default["name"], False)
  40. )
  41. return super(ResUser, self).copy(default)