diff --git a/partner_contact_gender/__init__.py b/partner_contact_gender/__init__.py index edd280109..aaf89bb3f 100644 --- a/partner_contact_gender/__init__.py +++ b/partner_contact_gender/__init__.py @@ -3,3 +3,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models +from hooks import post_init_hook diff --git a/partner_contact_gender/__openerp__.py b/partner_contact_gender/__openerp__.py index 1ab796ae3..0338c1a32 100644 --- a/partner_contact_gender/__openerp__.py +++ b/partner_contact_gender/__openerp__.py @@ -23,4 +23,5 @@ "data": [ "views/res_partner.xml", ], + 'post_init_hook': 'post_init_hook', } diff --git a/partner_contact_gender/hooks.py b/partner_contact_gender/hooks.py new file mode 100644 index 000000000..493dd7ef3 --- /dev/null +++ b/partner_contact_gender/hooks.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import api, SUPERUSER_ID + + +def post_init_hook(cr, pool): + env = api.Environment(cr, SUPERUSER_ID, {}) + gender_mappings = { + 'female': env.ref('base.res_partner_title_madam') + + env.ref('base.res_partner_title_miss'), + 'male': env.ref('base.res_partner_title_sir') + + env.ref('base.res_partner_title_mister'), + } + for gender, titles in gender_mappings.iteritems(): + env['res.partner'].with_context(active_test=False).search([ + ('title', 'in', titles.ids), + ]).write({ + 'gender': gender, + }) diff --git a/partner_contact_gender/tests/__init__.py b/partner_contact_gender/tests/__init__.py new file mode 100644 index 000000000..2b1cb9cfe --- /dev/null +++ b/partner_contact_gender/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_partner_contact_gender diff --git a/partner_contact_gender/tests/test_partner_contact_gender.py b/partner_contact_gender/tests/test_partner_contact_gender.py new file mode 100644 index 000000000..b19519f2d --- /dev/null +++ b/partner_contact_gender/tests/test_partner_contact_gender.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.tests.common import TransactionCase + + +class TestPartnerContactGender(TransactionCase): + def test_partner_contact_gender(self): + from ..hooks import post_init_hook + post_init_hook(self.cr, None)