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.

77 lines
3.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Yannick Vaucher
  5. # Copyright 2013 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm, fields
  22. class ResPartner(orm.Model):
  23. _inherit = 'res.partner'
  24. def _display_name_compute(self, cr, uid, ids, name, args, context=None):
  25. return dict(self.name_get(cr, uid, ids, context=context))
  26. def name_get(self, cr, uid, ids, context=None):
  27. """ By pass of name_get to use directly firstname and lastname
  28. as we cannot ensure name as already been computed when calling this
  29. method for display_name"""
  30. if context is None:
  31. context = {}
  32. if isinstance(ids, (int, long)):
  33. ids = [ids]
  34. res = []
  35. for record in self.browse(cr, uid, ids, context=context):
  36. name = self._prepare_name_custom(cr, uid, record, context=context)
  37. if record.parent_id and not record.is_company:
  38. name = "%s, %s" % (record.parent_id.name, name)
  39. if context.get('show_address'):
  40. name = name + "\n" + self._display_address(
  41. cr, uid, record, without_company=True, context=context
  42. )
  43. name = name.replace('\n\n', '\n')
  44. name = name.replace('\n\n', '\n')
  45. if context.get('show_email') and record.email:
  46. name = "%s <%s>" % (name, record.email)
  47. res.append((record.id, name))
  48. return res
  49. _display_name_store_triggers = {
  50. 'res.partner': (
  51. lambda self, cr, uid, ids, context=None:
  52. self.search(cr, uid, [
  53. ('id', 'child_of', ids)
  54. ]),
  55. ['parent_id', 'is_company', 'name', 'firstname', 'lastname'],
  56. 10
  57. )
  58. }
  59. # indirection to avoid passing a copy of the overridable method when
  60. # declaring the function field
  61. _display_name = lambda self, *a, **kw: self._display_name_compute(*a, **kw)
  62. _columns = {
  63. # extra field to allow ORDER BY to match visible names
  64. 'display_name': fields.function(
  65. _display_name,
  66. type='char',
  67. string='Name',
  68. store=_display_name_store_triggers
  69. ),
  70. }