Browse Source

[ADD] init hook to set gender based on titles

pull/279/head
Holger Brunn 9 years ago
parent
commit
b21e97c715
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  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. 10
      partner_contact_gender/tests/test_partner_contact_gender.py

1
partner_contact_gender/__init__.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

1
partner_contact_gender/__openerp__.py

@ -33,4 +33,5 @@
"data": [
"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

10
partner_contact_gender/tests/test_partner_contact_gender.py

@ -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)
Loading…
Cancel
Save