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.

37 lines
1.2 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. import logging
  7. from odoo import api, models
  8. _logger = logging.getLogger(__name__)
  9. class ResUser(models.Model):
  10. _inherit = 'res.users'
  11. @api.model
  12. def default_get(self, fields_list):
  13. """Invert name when getting default values."""
  14. result = super(ResUser, self).default_get(fields_list)
  15. partner_model = self.env['res.partner']
  16. inverted = partner_model._get_inverse_name(
  17. partner_model._get_whitespace_cleaned_name(result.get("name", "")),
  18. result.get("is_company", False))
  19. for field in inverted.keys():
  20. if field in fields_list:
  21. result[field] = inverted.get(field)
  22. return result
  23. @api.onchange("firstname", "lastname")
  24. def _compute_name(self):
  25. """Write the 'name' field according to splitted data."""
  26. for rec in self:
  27. rec.name = rec.partner_id._get_computed_name(
  28. rec.lastname, rec.firstname)