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.

50 lines
1.7 KiB

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