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.

36 lines
1.2 KiB

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