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.

73 lines
2.7 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  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 res_partner_address(orm.Model):
  23. _inherit = 'res.partner.address'
  24. _columns = {
  25. 'first_name': fields.char('First Name', size=128),
  26. 'last_name': fields.char('Last Name', size=128),
  27. 'name': fields.char('Name', size=128, readonly=True),
  28. }
  29. def write(self, cr, uid, ids, vals, context=None):
  30. if context is None:
  31. context = {}
  32. if isinstance(ids, list):
  33. ids = ids[0]
  34. data = self.read(cr, uid, ids, ['first_name', 'last_name'], context=context)
  35. first_name = data['first_name'] or ''
  36. if 'first_name' in vals:
  37. first_name = vals['first_name'] or ''
  38. last_name = data['last_name'] or ''
  39. if 'last_name' in vals:
  40. last_name = vals['last_name'] or ''
  41. if first_name or last_name:
  42. vals['name'] = first_name + ' ' + last_name
  43. return super(res_partner_address, self).write(cr, uid, ids, vals, context=context)
  44. def create(self, cr, uid, vals, context=None):
  45. if context is None:
  46. context = {}
  47. first_name = ''
  48. last_name = ''
  49. if 'first_name' in vals:
  50. first_name = vals['first_name'] or ''
  51. if 'last_name' in vals:
  52. last_name = vals['last_name'] or ''
  53. if first_name or last_name:
  54. vals['name'] = first_name + ' ' + last_name
  55. return super(res_partner_address, self).create(cr, uid, vals, context=context)
  56. def onchange_name(self, cr, uid, id, first_name, last_name):
  57. res = {}
  58. if not first_name:
  59. first_name = ''
  60. if not last_name:
  61. last_name = ''
  62. if first_name or last_name:
  63. res = {'name': first_name + ' ' + last_name}
  64. return {'value': res}