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.

45 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2013 Nicolas Bessi (Camptocamp SA)
  3. # © 2014 Agile Business Group (<http://www.agilebg.com>)
  4. # © 2015 Grupo ESOC (<http://www.grupoesoc.es>)
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from odoo import api, models, _
  7. class ResUser(models.Model):
  8. _inherit = 'res.users'
  9. @api.model
  10. def default_get(self, fields_list):
  11. """Invert name when getting default values."""
  12. result = super(ResUser, self).default_get(fields_list)
  13. partner_model = self.env['res.partner']
  14. inverted = partner_model._get_inverse_name(
  15. partner_model._get_whitespace_cleaned_name(result.get("name", "")),
  16. result.get("is_company", False))
  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(
  26. rec.lastname, rec.firstname)
  27. @api.multi
  28. def copy(self, default=None):
  29. self.ensure_one()
  30. default = dict(default or {})
  31. if ('name' not in default) and ('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 ('lastname' not in default) and ('name' in default):
  36. default.update(self.env['res.partner']._get_inverse_name(default['name'], False))
  37. return super(ResUser, self).copy(default)