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.

64 lines
2.4 KiB

10 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Nicolas Bessi. Copyright Camptocamp SA
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp.osv import orm
  21. from openerp.tools.translate import _
  22. class ResUsers(orm.Model):
  23. _inherit = 'res.users'
  24. def create(self, cr, user, vals, context=None):
  25. """To support data backward compatibility we have to keep this
  26. overwrite even if we use fnct_inv: otherwise we can't create
  27. entry because lastname is mandatory and module will not install
  28. if there is demo data
  29. This fixes the unittests in stock when partner_firstname is
  30. installed
  31. """
  32. vals2 = vals.copy()
  33. if 'name' in vals:
  34. vals2['lastname'] = vals2['name']
  35. elif 'login' in vals and 'lastname' not in vals:
  36. vals2['lastname'] = vals2['login']
  37. return super(ResUsers, self).create(cr, user, vals2, context=context)
  38. def copy_data(self, cr, uid, _id, default=None, context=None):
  39. """Avoid to replicate the firstname into the name when
  40. duplicating a user
  41. """
  42. default = default or {}
  43. if not default.get('lastname'):
  44. default = default.copy()
  45. default['lastname'] = (
  46. _('%s (copy)') % self.read(
  47. cr,
  48. uid,
  49. [_id],
  50. ['lastname'],
  51. context=context
  52. )[0]['lastname']
  53. )
  54. if default.get('name'):
  55. del(default['name'])
  56. return super(ResUsers, self).copy_data(
  57. cr, uid, _id, default, context=context
  58. )