Browse Source

[IMP] partner_helper: black, isort, prettier

14.0
Florian da Costa 4 years ago
parent
commit
2b060721d6
  1. 24
      partner_helper/__manifest__.py
  2. 31
      partner_helper/models/partner.py
  3. 16
      partner_helper/tests/test_split_address.py
  4. 1
      setup/partner_helper/odoo/addons/partner_helper
  5. 6
      setup/partner_helper/setup.py

24
partner_helper/__manifest__.py

@ -1,17 +1,17 @@
# Author: Sébastien BEAU <sebastien.beau@akretion.com>
# 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",
}

31
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)

16
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)

1
setup/partner_helper/odoo/addons/partner_helper

@ -0,0 +1 @@
../../../../partner_helper

6
setup/partner_helper/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save