Browse Source

[ADD] init hook to set gender based on titles

pull/713/head
Holger Brunn 9 years ago
committed by Oihane Crucelaegui
parent
commit
1ace39c695
  1. 1
      partner_contact_gender/__init__.py
  2. 1
      partner_contact_gender/__openerp__.py
  3. 20
      partner_contact_gender/hooks.py
  4. 4
      partner_contact_gender/tests/__init__.py
  5. 18
      partner_contact_gender/tests/test_partner_contact_gender.py

1
partner_contact_gender/__init__.py

@ -3,3 +3,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models from . import models
from .hooks import post_init_hook

1
partner_contact_gender/__openerp__.py

@ -23,4 +23,5 @@
"data": [ "data": [
"views/res_partner.xml", "views/res_partner.xml",
], ],
'post_init_hook': 'post_init_hook',
} }

20
partner_contact_gender/hooks.py

@ -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,
})

4
partner_contact_gender/tests/__init__.py

@ -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

18
partner_contact_gender/tests/test_partner_contact_gender.py

@ -0,0 +1,18 @@
# -*- 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 setUp(self):
super(TestPartnerContactGender, self).setUp()
self.testpartner = self.env['res.partner'].create({
'name': 'test',
'title': self.env.ref('base.res_partner_title_madam').id,
})
def test_partner_contact_gender(self):
from ..hooks import post_init_hook
post_init_hook(self.cr, None)
self.assertEqual(self.testpartner.gender, 'female')
Loading…
Cancel
Save