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.

49 lines
1.6 KiB

  1. # Copyright (C) 2016 Akretion (http://www.akretion.com)
  2. # Author: Sébastien BEAU <sebastien.beau@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models
  5. def split_char(char, output_number, size):
  6. words = char.split(' ')
  7. result = []
  8. word = words.pop(0)
  9. for index in range(0, output_number):
  10. result.append(word)
  11. word = ''
  12. while len(words) > 0:
  13. word = words.pop(0)
  14. if len(result[index] + ' %s' % word) > size:
  15. break
  16. else:
  17. result[index] += ' %s' % word
  18. word = ''
  19. return result
  20. class ResPartner(models.Model):
  21. _inherit = "res.partner"
  22. def _get_split_address(self, output_number, max_size):
  23. """ This method allows to get a number of street fields according to
  24. your choice. Default is 2 large fields in Odoo (128 chars).
  25. In some countries you may use 3 or 4 shorter street fields.
  26. example:
  27. res = self.partner_id._get_split_address(3, 35)
  28. street1, street2, street3 = res
  29. """
  30. self.ensure_one()
  31. street = self.street or ''
  32. street2 = self.street2 or ''
  33. if len(street) <= max_size and len(street2) <= max_size:
  34. result = ['' for i in range(0, output_number)]
  35. result[0] = street
  36. result[1] = street2
  37. return result
  38. elif len(street) <= max_size:
  39. return [street] + split_char(street2, output_number - 1, max_size)
  40. else:
  41. return split_char(
  42. '%s %s' % (street, street2), output_number, max_size)