From 817849d53b16a751702a6625b95637233c9dc53b Mon Sep 17 00:00:00 2001 From: MonsieurB Date: Wed, 5 Apr 2017 17:11:33 +0200 Subject: [PATCH] [MIG] partner_helper: Migration to 10.0 (#386) * Migrate to V10 * Tests * Remove method args not necessary with new api --- partner_helper/README.rst | 63 ++++++++++++++++++++++ partner_helper/__init__.py | 21 +------- partner_helper/__manifest__.py | 52 ++---------------- partner_helper/partner.py | 37 ++++--------- partner_helper/tests/__init__.py | 5 ++ partner_helper/tests/test_split_address.py | 22 ++++++++ 6 files changed, 106 insertions(+), 94 deletions(-) create mode 100644 partner_helper/README.rst create mode 100644 partner_helper/tests/__init__.py create mode 100644 partner_helper/tests/test_split_address.py diff --git a/partner_helper/README.rst b/partner_helper/README.rst new file mode 100644 index 000000000..28e81cd8d --- /dev/null +++ b/partner_helper/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== +Partner Helper +============== + +The purpose of this module is to gather generic partner methods. +It avoids to grow up excessively the number of modules in Odoo +for small features. + +Description +----------- +Add specific helper methods to deal with partners: + +* _get_split_address(): + This method allows to get a number of street fields according to + your choice. 2 fields by default in Odoo with 128 width chars. + In some countries you have constraints on width of street fields and you + should use 3 or 4 shorter fields. + You also need of this feature to avoid headache with overflow printing task + +* other_method(): + + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + + +Images +------ + +* Odoo Community Association: `Icon `_. + + +Contributors +------------ + + * Sébastien BEAU + * David BEAL + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/partner_helper/__init__.py b/partner_helper/__init__.py index 590716ea0..e965bbdc1 100644 --- a/partner_helper/__init__.py +++ b/partner_helper/__init__.py @@ -1,22 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## -# # Author: Sébastien BEAU -# Copyright 2014 Akretion -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import partner # noqa +from . import partner diff --git a/partner_helper/__manifest__.py b/partner_helper/__manifest__.py index a8410b6e3..948459aed 100644 --- a/partner_helper/__manifest__.py +++ b/partner_helper/__manifest__.py @@ -1,64 +1,20 @@ # -*- coding: utf-8 -*- -############################################################################## -# # Author: Sébastien BEAU -# Copyright 2014 Akretion -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Partner Helper', - 'version': '8.0.0.1.0', + 'version': '10.0.0.1.0', 'author': "Akretion,Odoo Community Association (OCA)", 'maintainer': 'Akretion', 'category': 'Warehouse', 'depends': [ 'base', ], - 'description': """ -Partner Helper -============== -The purpose of this module is to gather generic partner methods. -It avoids to grow up excessively the number of modules in Odoo -for small features. - -Description ------------ -Add specific helper methods to deal with partners: - -* _get_split_address(): - This method allows to get a number of street fields according to - your choice. 2 fields by default in Odoo with 128 width chars. - In some countries you have constraints on width of street fields and you - should use 3 or 4 shorter fields. - You also need of this feature to avoid headache with overflow printing task - -* other_method(): - -Contributors ------------- -* Sébastien BEAU -* David BEAL - - - """, + 'summary': "Add specific helper methods", 'website': 'http://www.akretion.com/', 'data': [], 'tests': [], - 'installable': False, + 'installable': True, 'auto_install': False, 'license': 'AGPL-3', 'application': False, diff --git a/partner_helper/partner.py b/partner_helper/partner.py index 569bf5dc7..8dd3d0168 100644 --- a/partner_helper/partner.py +++ b/partner_helper/partner.py @@ -1,25 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# +# Copyright (C) 2016 Akretion (http://www.akretion.com) # Author: Sébastien BEAU -# Copyright 2014 Akretion -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.osv import orm +from odoo import models def split_char(char, output_number, size): @@ -39,22 +23,21 @@ def split_char(char, output_number, size): return result -class ResPartner(orm.Model): +class ResPartner(models.Model): _inherit = "res.partner" - def _get_split_address( - self, cr, uid, partner, output_number, max_size, context=None): + 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. example: - res = self.pool['res.partner']._get_split_address( - cr, uid, picking.partner_id, 3, 35, context=context) - address['street'], address['street2'], address['street3'] = res + res = self.env['res.partner']._get_split_address( 3, 35) + street1, street2, street3 = res """ - street = partner.street or '' - street2 = partner.street2 or '' + self.ensure_one() + 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[0] = street diff --git a/partner_helper/tests/__init__.py b/partner_helper/tests/__init__.py new file mode 100644 index 000000000..d3e589cdc --- /dev/null +++ b/partner_helper/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Author: Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_split_address diff --git a/partner_helper/tests/test_split_address.py b/partner_helper/tests/test_split_address.py new file mode 100644 index 000000000..19da047fc --- /dev/null +++ b/partner_helper/tests/test_split_address.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from openerp.tests.common import TransactionCase +import logging +_logger = logging.getLogger(__name__) + + +class TestSplit(TransactionCase): + + def setUp(self): + super(TestSplit, self).setUp() + self.partnerX = self.env.ref('base.res_partner_12') + + def test_init1(self): + address = u"278 route pitoresque de la vallee de" \ + u" l'ours qui fuit les chasseurs" + partner = self.partnerX + partner.street = address + address1, address2 = partner._get_split_address(2, 40) + self.assertEqual('278 route pitoresque de la vallee de', address1) + self.assertEqual(u"l'ours qui fuit les chasseurs ", address2) + self.assertTrue(len(address1) <= 40) + self.assertTrue(len(address2) <= 40)