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.3 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api, _
  3. from openerp.exceptions import ValidationError
  4. def concat_names(*args):
  5. """
  6. Concatenate only args that are not empty
  7. @param args: a list of string
  8. """
  9. return ' '.join(filter(bool, args))
  10. class Partner(models.Model):
  11. _inherit = 'res.partner'
  12. firstname = fields.Char('First Name')
  13. lastname = fields.Char('Last Name', required=True, default="/")
  14. name = fields.Char(compute='_get_name', inverse='_set_name', store=True, string="Full Name")
  15. @api.depends('firstname', 'lastname')
  16. def _get_name(self):
  17. for rec in self:
  18. rec.name = concat_names(rec.firstname, rec.lastname)
  19. def _set_name(self):
  20. """
  21. This allow to handle the case of code that write directly on the name at creation
  22. Should never happen but in case it happen write on the lastname
  23. If there is no firstname lastname and name are the same
  24. """
  25. for rec in self:
  26. if not rec.firstname:
  27. rec.lastname = rec.name
  28. #Compatibility with old name use in beedoo
  29. last_name = fields.Char(related='lastname', string="Last Name (Legacy)")
  30. first_name = fields.Char(related='firstname', string="Frist Name (Legacy)")