Browse Source
[10.0] Port partner_address_street3 (#318)
[10.0] Port partner_address_street3 (#318)
Add %(street3)s in 'address_format' of existing countriespull/690/head
Alexis de Lattre
8 years ago
committed by
hveficent
11 changed files with 125 additions and 219 deletions
-
16partner_address_street3/README.rst
-
22partner_address_street3/__init__.py
-
20partner_address_street3/__manifest__.py
-
37partner_address_street3/__openerp__.py
-
41partner_address_street3/hooks.py
-
21partner_address_street3/model/__init__.py
-
19partner_address_street3/model/country.py
-
41partner_address_street3/model/partner.py
-
20partner_address_street3/tests/__init__.py
-
94partner_address_street3/tests/test_street_3.py
-
13partner_address_street3/view/partner_view.xml
@ -1,21 +1,5 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# Author: Nicolas Bessi |
|
||||
# Copyright 2014 Camptocamp SA |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import model |
from . import model |
||||
|
from .hooks import post_init_hook |
||||
|
from .hooks import uninstall_hook |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2014-2016 Camptocamp SA |
||||
|
# @author: Nicolas Bessi |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
{ |
||||
|
'name': 'Street3 in addresses', |
||||
|
'summary': 'Add a third address line on partners', |
||||
|
'license': 'AGPL-3', |
||||
|
'version': '10.0.1.0.0', |
||||
|
'author': "Camptocamp,Odoo Community Association (OCA)", |
||||
|
'maintainer': 'Camptocamp', |
||||
|
'category': 'Sales', |
||||
|
'depends': ['base'], |
||||
|
'website': 'http://www.camptocamp.com', |
||||
|
'data': ['view/partner_view.xml'], |
||||
|
'post_init_hook': 'post_init_hook', |
||||
|
'uninstall_hook': 'uninstall_hook', |
||||
|
'installable': True, |
||||
|
} |
@ -1,37 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# Author: Nicolas Bessi |
|
||||
# Copyright 2014 Camptocamp SA |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
{ |
|
||||
'name': 'Street3 in addresses', |
|
||||
'version': '8.0.0.1.0', |
|
||||
'author': "Camptocamp,Odoo Community Association (OCA)", |
|
||||
'maintainer': 'Camptocamp', |
|
||||
'category': 'Sales', |
|
||||
'complexity': 'easy', |
|
||||
'depends': ['base'], |
|
||||
'website': 'http://www.camptocamp.com', |
|
||||
'data': ['view/partner_view.xml'], |
|
||||
'demo': [], |
|
||||
'test': [], |
|
||||
'installable': True, |
|
||||
'auto_install': False, |
|
||||
'license': 'AGPL-3', |
|
||||
'application': False, |
|
||||
} |
|
@ -0,0 +1,41 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2016 Sodexis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
|
||||
|
def post_init_hook(cr, registry): |
||||
|
""" Add street3 to address format """ |
||||
|
query = """ |
||||
|
UPDATE res_country |
||||
|
SET address_format = replace( |
||||
|
address_format, |
||||
|
E'%(street2)s\n', |
||||
|
E'%(street2)s\n%(street3)s\n' |
||||
|
) |
||||
|
""" |
||||
|
cr.execute(query) |
||||
|
|
||||
|
|
||||
|
def uninstall_hook(cr, registry): |
||||
|
""" Remove street3 from address format """ |
||||
|
# Remove %(street3)s\n from address_format |
||||
|
query = """ |
||||
|
UPDATE res_country |
||||
|
SET address_format = replace( |
||||
|
address_format, |
||||
|
E'%(street3)s\n', |
||||
|
'' |
||||
|
) |
||||
|
""" |
||||
|
cr.execute(query) |
||||
|
|
||||
|
# Remove %(street3)s from address_format |
||||
|
query = """ |
||||
|
UPDATE res_country |
||||
|
SET address_format = replace( |
||||
|
address_format, |
||||
|
E'%(street3)s', |
||||
|
'' |
||||
|
) |
||||
|
""" |
||||
|
cr.execute(query) |
@ -1,21 +1,4 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# Author: Nicolas Bessi |
|
||||
# Copyright 2014 Camptocamp SA |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import partner |
from . import partner |
||||
|
from . import country |
@ -0,0 +1,19 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2014-2016 Camptocamp SA |
||||
|
# @author: Nicolas Bessi |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import models, fields |
||||
|
|
||||
|
|
||||
|
class ResCountry(models.Model): |
||||
|
"""Override default adresses formatting of countries""" |
||||
|
_inherit = 'res.country' |
||||
|
|
||||
|
address_format = fields.Text( |
||||
|
default=( |
||||
|
"%(street)s\n%(street2)s\n%(street3)s\n" |
||||
|
"%(city)s %(state_code)s %(zip)s\n" |
||||
|
"%(country_name)s" |
||||
|
) |
||||
|
) |
@ -1,21 +1,3 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# Author: Nicolas Bessi |
|
||||
# Copyright 2014 Camptocamp SA |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import test_street_3 |
from . import test_street_3 |
@ -1,88 +1,36 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# Author: Nicolas Bessi |
|
||||
# Copyright 2014 Camptocamp SA |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
import openerp.tests.common as test_common |
|
||||
|
# © 2014-2016 Camptocamp SA |
||||
|
# @author: Nicolas Bessi |
||||
|
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo.tests.common import TransactionCase |
||||
|
|
||||
class TestStreet3(test_common.TransactionCase): |
|
||||
|
|
||||
def test_partner(self): |
|
||||
part_model = self.registry('res.partner') |
|
||||
country_model = self.registry('res.country') |
|
||||
country_id = country_model.create( |
|
||||
self.cr, |
|
||||
self.uid, |
|
||||
{ |
|
||||
'name': 'Donut Land', |
|
||||
'code': 'DNL', |
|
||||
} |
|
||||
) |
|
||||
|
class TestStreet3(TransactionCase): |
||||
|
|
||||
self.assertTrue(country_id) |
|
||||
|
def test_partner(self): |
||||
|
# Test address_format has been updated on existing countries |
||||
|
us_country = self.env.ref('base.us') |
||||
|
self.assertTrue('%(street3)s' in us_country.address_format) |
||||
|
|
||||
create_data = { |
|
||||
|
homer = self.env['res.partner'].create({ |
||||
'name': 'Homer Simpson', |
'name': 'Homer Simpson', |
||||
'city': 'Springfield', |
'city': 'Springfield', |
||||
'street': '742 Evergreen Terrace', |
'street': '742 Evergreen Terrace', |
||||
'street2': 'Donut Lane', |
'street2': 'Donut Lane', |
||||
'street3': 'Tho', |
'street3': 'Tho', |
||||
'country_id': country_id, |
|
||||
'is_company': True |
|
||||
} |
|
||||
|
|
||||
homer_id = part_model.create( |
|
||||
self.cr, |
|
||||
self.uid, |
|
||||
create_data |
|
||||
) |
|
||||
|
|
||||
homer = part_model.browse( |
|
||||
self.cr, |
|
||||
self.uid, |
|
||||
homer_id, |
|
||||
) |
|
||||
|
'country_id': us_country.id, |
||||
|
}) |
||||
|
|
||||
self.assertEqual( |
|
||||
homer.country_id.address_format, |
|
||||
("%(street)s\n%(street2)s\n%(street3)s\n" |
|
||||
"%(city)s %(state_code)s %(zip)s\n" |
|
||||
"%(country_name)s") |
|
||||
) |
|
||||
|
|
||||
create_data = { |
|
||||
|
# test synchro of street3 on create |
||||
|
bart = self.env['res.partner'].create({ |
||||
'name': 'Bart Simpson', |
'name': 'Bart Simpson', |
||||
'is_company': False, |
|
||||
'parent_id': homer.id, |
'parent_id': homer.id, |
||||
'use_parent_address': True |
|
||||
} |
|
||||
|
|
||||
bart_id = part_model.create( |
|
||||
self.cr, |
|
||||
self.uid, |
|
||||
create_data |
|
||||
) |
|
||||
|
|
||||
bart = part_model.browse( |
|
||||
self.cr, |
|
||||
self.uid, |
|
||||
bart_id, |
|
||||
) |
|
||||
|
'type': 'contact', |
||||
|
}) |
||||
|
self.assertEquals(bart.street3, 'Tho') |
||||
|
|
||||
self.assertTrue(bart.street3, 'Tho') |
|
||||
|
# test synchro of street3 on write |
||||
|
homer.write({'street3': 'in OCA we trust'}) |
||||
|
self.assertEquals(bart.street3, 'in OCA we trust') |
Write
Preview
Loading…
Cancel
Save
Reference in new issue