Browse Source
[ADD] init hook to set gender based on titles
pull/279/head
Holger Brunn
9 years ago
No known key found for this signature in database
GPG Key ID: 1C9760FECA3AE18
5 changed files with
36 additions and
0 deletions
-
partner_contact_gender/__init__.py
-
partner_contact_gender/__openerp__.py
-
partner_contact_gender/hooks.py
-
partner_contact_gender/tests/__init__.py
-
partner_contact_gender/tests/test_partner_contact_gender.py
|
|
@ -17,3 +17,4 @@ |
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
from . import models |
|
|
|
from hooks import post_init_hook |
|
|
@ -33,4 +33,5 @@ |
|
|
|
"data": [ |
|
|
|
"views/res_partner.xml", |
|
|
|
], |
|
|
|
'post_init_hook': 'post_init_hook', |
|
|
|
} |
|
|
@ -0,0 +1,20 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Therp BV <http://therp.nl> |
|
|
|
# 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, |
|
|
|
}) |
|
|
@ -0,0 +1,4 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Therp BV <http://therp.nl> |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
from . import test_partner_contact_gender |
|
|
@ -0,0 +1,10 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Therp BV <http://therp.nl> |
|
|
|
# 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) |