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.8 KiB

6 years ago
6 years ago
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. for field in list(inverted.keys()):
  17. if field in fields_list:
  18. result[field] = inverted.get(field)
  19. return result
  20. @api.onchange("firstname", "lastname")
  21. def _compute_name(self):
  22. """Write the 'name' field according to splitted data."""
  23. for rec in self:
  24. rec.name = rec.partner_id._get_computed_name(
  25. rec.lastname, rec.firstname)
  26. @api.model
  27. def copy(self, default=None):
  28. self.ensure_one()
  29. default = dict(default or {})
  30. if (('name' not in default) and
  31. ('partner_id' not in default)):
  32. default['name'] = _("%s (copy)") % self.name
  33. if 'login' not in default:
  34. default['login'] = _("%s (copy)") % self.login
  35. if (('firstname' not in default) and
  36. ('lastname' not in default) and
  37. ('name' in default)):
  38. default.update(self.env['res.partner']._get_inverse_name(
  39. default['name'], False)
  40. )
  41. return super(ResUser, self).copy(default)