diff --git a/partner_helper/__manifest__.py b/partner_helper/__manifest__.py index 04b7a9493..e44aa8f07 100644 --- a/partner_helper/__manifest__.py +++ b/partner_helper/__manifest__.py @@ -1,17 +1,17 @@ # Author: Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Partner Helper', - 'version': '12.0.0.1.0', - 'author': "Akretion,Odoo Community Association (OCA)", - 'maintainer': 'Akretion', - 'category': 'Warehouse', - 'depends': [ - 'base', + "name": "Partner Helper", + "version": "12.0.0.1.0", + "author": "Akretion,Odoo Community Association (OCA)", + "maintainer": "Akretion", + "category": "Warehouse", + "depends": [ + "base", ], - 'summary': "Add specific helper methods", - 'website': 'http://www.akretion.com/', - 'installable': True, - 'auto_install': False, - 'license': 'AGPL-3', + "summary": "Add specific helper methods", + "website": "https://github.com/OCA/partner-contact", + "installable": True, + "auto_install": False, + "license": "AGPL-3", } diff --git a/partner_helper/models/partner.py b/partner_helper/models/partner.py index 5266472d5..0baa57bb5 100644 --- a/partner_helper/models/partner.py +++ b/partner_helper/models/partner.py @@ -6,19 +6,19 @@ from odoo import models def split_char(char, output_number, size): - words = char.split(' ') + words = char.split(" ") result = [] word = words.pop(0) for index in range(0, output_number): result.append(word) - word = '' + word = "" while len(words) > 0: word = words.pop(0) - if len(result[index] + ' %s' % word) > size: + if len(result[index] + " %s" % word) > size: break else: - result[index] += ' %s' % word - word = '' + result[index] += " %s" % word + word = "" return result @@ -26,24 +26,23 @@ class ResPartner(models.Model): _inherit = "res.partner" def _get_split_address(self, output_number, max_size): - """ This method allows to get a number of street fields according to - your choice. Default is 2 large fields in Odoo (128 chars). - In some countries you may use 3 or 4 shorter street fields. + """This method allows to get a number of street fields according to + your choice. Default is 2 large fields in Odoo (128 chars). + In some countries you may use 3 or 4 shorter street fields. - example: - res = self.partner_id._get_split_address(3, 35) - street1, street2, street3 = res + example: + res = self.partner_id._get_split_address(3, 35) + street1, street2, street3 = res """ self.ensure_one() - street = self.street or '' - street2 = self.street2 or '' + street = self.street or "" + street2 = self.street2 or "" if len(street) <= max_size and len(street2) <= max_size: - result = ['' for i in range(0, output_number)] + result = ["" for i in range(0, output_number)] result[0] = street result[1] = street2 return result elif len(street) <= max_size: return [street] + split_char(street2, output_number - 1, max_size) else: - return split_char( - '%s %s' % (street, street2), output_number, max_size) + return split_char("{} {}".format(street, street2), output_number, max_size) diff --git a/partner_helper/tests/test_split_address.py b/partner_helper/tests/test_split_address.py index acaee0c06..456904b78 100644 --- a/partner_helper/tests/test_split_address.py +++ b/partner_helper/tests/test_split_address.py @@ -1,26 +1,28 @@ -from odoo.tests.common import TransactionCase import logging + +from odoo.tests.common import TransactionCase + _logger = logging.getLogger(__name__) class TestSplit(TransactionCase): - def setUp(self): super(TestSplit, self).setUp() - self.partnerX = self.env.ref('base.res_partner_12') - self.partnerX.street = "278 route pitoresque de la vallee de" \ - " l'ours qui fuit les chasseurs" + self.partnerX = self.env.ref("base.res_partner_12") + self.partnerX.street = ( + "278 route pitoresque de la vallee de" " l'ours qui fuit les chasseurs" + ) def test_split1(self): address1, address2 = self.partnerX._get_split_address(2, 40) - self.assertEqual('278 route pitoresque de la vallee de', address1) + self.assertEqual("278 route pitoresque de la vallee de", address1) self.assertEqual("l'ours qui fuit les chasseurs ", address2) self.assertTrue(len(address1) <= 40) self.assertTrue(len(address2) <= 40) def test_split2(self): address1, address2, address3 = self.partnerX._get_split_address(3, 25) - self.assertEqual('278 route pitoresque de', address1) + self.assertEqual("278 route pitoresque de", address1) self.assertEqual("la vallee de l'ours qui", address2) self.assertEqual("fuit les chasseurs ", address3) self.assertTrue(len(address1) <= 25) diff --git a/setup/partner_helper/odoo/addons/partner_helper b/setup/partner_helper/odoo/addons/partner_helper new file mode 120000 index 000000000..6f909492b --- /dev/null +++ b/setup/partner_helper/odoo/addons/partner_helper @@ -0,0 +1 @@ +../../../../partner_helper \ No newline at end of file diff --git a/setup/partner_helper/setup.py b/setup/partner_helper/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/partner_helper/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)