Browse Source

[ADD] init hook to set gender based on titles

pull/280/head
Holger Brunn 9 years ago
parent
commit
301560e89f
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

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

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