From 817a8196c9a77acfefa957fdef38447f6f8baa4e Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Mon, 21 Oct 2013 10:55:46 +0200 Subject: [PATCH 1/5] [+] base_contact module --- base_contact/__init__.py | 23 +++ base_contact/__openerp__.py | 52 ++++++ base_contact/base_contact.py | 138 ++++++++++++++++ base_contact/base_contact_demo.xml | 29 ++++ base_contact/base_contact_view.xml | 201 ++++++++++++++++++++++++ base_contact/tests/__init__.py | 26 +++ base_contact/tests/test_base_contact.py | 101 ++++++++++++ 7 files changed, 570 insertions(+) create mode 100644 base_contact/__init__.py create mode 100644 base_contact/__openerp__.py create mode 100644 base_contact/base_contact.py create mode 100644 base_contact/base_contact_demo.xml create mode 100644 base_contact/base_contact_view.xml create mode 100644 base_contact/tests/__init__.py create mode 100644 base_contact/tests/test_base_contact.py diff --git a/base_contact/__init__.py b/base_contact/__init__.py new file mode 100644 index 000000000..a93921487 --- /dev/null +++ b/base_contact/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-TODAY OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import base_contact + diff --git a/base_contact/__openerp__.py b/base_contact/__openerp__.py new file mode 100644 index 000000000..f53174dbe --- /dev/null +++ b/base_contact/__openerp__.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (C) 2013-TODAY OpenERP S.A. (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Contacts Management', + 'version': '1.0', + 'category': 'Customer Relationship Management', + 'complexity': "expert", + 'description': """ +This module allows you to manage your contacts +============================================== + +It lets you define groups of contacts sharing some common information, like: + * Birthdate + * Nationality + * Native Language + + """, + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': ['base', 'process', 'contacts'], + 'init_xml': [], + 'update_xml': [ + 'base_contact_view.xml', + ], + 'demo_xml': [ + 'base_contact_demo.xml', + ], + 'installable': True, + 'auto_install': False, + #'certificate': '0031287885469', + 'images': [], +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_contact/base_contact.py b/base_contact/base_contact.py new file mode 100644 index 000000000..cb4b79439 --- /dev/null +++ b/base_contact/base_contact.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-TODAY OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import fields, osv, expression + + +class res_partner(osv.osv): + _inherit = 'res.partner' + + _contact_type = [ + ('standalone', 'Standalone Contact'), + ('attached', 'Attached to existing Contact'), + ] + + def _get_contact_type(self, cr, uid, ids, field_name, args, context=None): + result = dict.fromkeys(ids, 'standalone') + for partner in self.browse(cr, uid, ids, context=context): + if partner.contact_id: + result[partner.id] = 'attached' + return result + + _columns = { + 'contact_type': fields.function(_get_contact_type, type='selection', selection=_contact_type, + string='Contact Type', required=True, select=1, store=True), + 'contact_id': fields.many2one('res.partner', 'Main Contact', + domain=[('is_company','=',False),('contact_type','=','standalone')]), + 'other_contact_ids': fields.one2many('res.partner', 'contact_id', 'Others Positions'), + + # Person specific fields + 'birthdate_date': fields.date('Birthdate'), # add a 'birthdate' as date field, i.e different from char 'birthdate' introduced v6.1! + 'nationality_id': fields.many2one('res.country', 'Nationality'), + } + + _defaults = { + 'contact_type': 'standalone', + } + + def _basecontact_check_context(self, cr, user, mode, context=None): + if context is None: + context = {} + # Remove 'search_show_all_positions' for non-search mode. + # Keeping it in context can result in unexpected behaviour (ex: reading + # one2many might return wrong result - i.e with "attached contact" removed + # even if it's directly linked to a company). + if mode != 'search': + context.pop('search_show_all_positions', None) + return context + + def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False): + if context is None: + context = {} + if context.get('search_show_all_positions') is False: + # display only standalone contact matching ``args`` or having + # attached contact matching ``args`` + args = expression.normalize_domain(args) + attached_contact_args = expression.AND((args, [('contact_type', '=', 'attached')])) + attached_contact_ids = super(res_partner, self).search(cr, user, attached_contact_args, + context=context) + args = expression.OR(( + expression.AND(([('contact_type', '=', 'standalone')], args)), + [('other_contact_ids', 'in', attached_contact_ids)], + )) + return super(res_partner, self).search(cr, user, args, offset=offset, limit=limit, + order=order, context=context, count=count) + + def create(self, cr, user, vals, context=None): + context = self._basecontact_check_context(cr, user, 'create', context) + if not vals.get('name') and vals.get('contact_id'): + vals['name'] = self.browse(cr, user, vals['contact_id'], context=context) + return super(res_partner, self).create(cr, user, vals, context=context) + + def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): + context = self._basecontact_check_context(cr, user, 'read', context) + return super(res_partner, self).read(cr, user, ids, fields=fields, context=context, load=load) + + def write(self, cr, user, ids, vals, context=None): + context = self._basecontact_check_context(cr, user, 'write', context) + return super(res_partner, self).write(cr, user, ids, vals, context=context) + + def unlink(self, cr, user, ids, context=None): + context = self._basecontact_check_context(cr, user, 'unlink', context) + return super(res_partner, self).unlink(cr, user, ids, context=context) + + def _commercial_partner_compute(self, cr, uid, ids, name, args, context=None): + """ Returns the partner that is considered the commercial + entity of this partner. The commercial entity holds the master data + for all commercial fields (see :py:meth:`~_commercial_fields`) """ + result = super(res_partner, self)._commercial_partner_compute(cr, uid, ids, name, args, context=context) + for partner in self.browse(cr, uid, ids, context=context): + if partner.contact_type == 'attached' and not partner.parent_id: + result[partner.id] = partner.contact_id.id + return result + + def onchange_contact_id(self, cr, uid, ids, contact_id, context=None): + if contact_id: + name = self.browse(cr, uid, contact_id, context=context).name + return {'value': {'name': name}} + return {} + + +class ir_actions_window(osv.osv): + _inherit = 'ir.actions.act_window' + + def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): + action_ids = ids + if isinstance(ids, (int, long)): + action_ids = [ids] + actions = super(ir_actions_window, self).read(cr, user, action_ids, fields=fields, context=context, load=load) + for action in actions: + if action.get('res_model', '') == 'res.partner': + # By default, only show standalone contact + action_context = action.get('context', '{}') or '{}' + if 'search_show_all_positions' not in action_context: + action['context'] = action_context.replace('{', + "{'search_show_all_positions': False,", 1) + if isinstance(ids, (int, long)): + if actions: + return actions[0] + return False + return actions diff --git a/base_contact/base_contact_demo.xml b/base_contact/base_contact_demo.xml new file mode 100644 index 000000000..a7af9373f --- /dev/null +++ b/base_contact/base_contact_demo.xml @@ -0,0 +1,29 @@ + + + + + + Roger Scott + Consultant + + + + + + + Bob Egnops + 1984-01-01 + bob@hillenburg-oceaninstitute.com + + + + Bob Egnops + Technician + bob@yourcompany.com + + + + + + + \ No newline at end of file diff --git a/base_contact/base_contact_view.xml b/base_contact/base_contact_view.xml new file mode 100644 index 000000000..93eeac5aa --- /dev/null +++ b/base_contact/base_contact_view.xml @@ -0,0 +1,201 @@ + + + + + + res.partner.select.contact + res.partner + + + + + + + + + + + + + + res.partner.tree.contact + res.partner + + + + + + + + + + res.partner.form.contact + res.partner + + form + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ X +
+ + + + + + + + + + + + + + + + +
+
+ + + + +
+

+ + + + at + + +
Phone:
+
Mobile:
+
Fax:
+
+
+
+
+
+
+
+
+
+ + +
+
+ + + + + + + + + + +
+
+ + + +
+
+
+
+ +

+ To see personal information about this contact, please go to to the his person form: +

+ + + + +
+
+ + + + + + + + {'invisible': [('contact_type','=','attached')]} + +
+
+ + + res.partner.kanban.contact + res.partner + + + + + + + + + + + + +
  • + + other position + other positions
  • +
    +
    +
    +
    + +
    +
    diff --git a/base_contact/tests/__init__.py b/base_contact/tests/__init__.py new file mode 100644 index 000000000..fbadb7091 --- /dev/null +++ b/base_contact/tests/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 ⁻*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (C) 2013-TODAY OpenERP S.A. (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_base_contact + +checks = [ + test_base_contact, +] diff --git a/base_contact/tests/test_base_contact.py b/base_contact/tests/test_base_contact.py new file mode 100644 index 000000000..0f29a5dc0 --- /dev/null +++ b/base_contact/tests/test_base_contact.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 ⁻*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (C) 2013-TODAY OpenERP S.A. (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests import common + + +class Test_Base_Contact(common.TransactionCase): + + def setUp(self): + """*****setUp*****""" + super(Test_Base_Contact, self).setUp() + cr, uid = self.cr, self.uid + ModelData = self.registry('ir.model.data') + self.partner = self.registry('res.partner') + + # Get test records reference + for attr, module, name in [ + ('main_partner_id', 'base', 'main_partner'), + ('bob_contact_id', 'base_contact', 'res_partner_contact1'), + ('bob_job1_id', 'base_contact', 'res_partner_contact1_work_position1'), + ('roger_contact_id', 'base', 'res_partner_main2'), + ('roger_job2_id', 'base_contact', 'res_partner_main2_position_consultant')]: + r = ModelData.get_object_reference(cr, uid, module, name) + setattr(self, attr, r[1] if r else False) + + def test_00_show_only_standalone_contact(self): + """Check that only standalone contact are shown if context explicitly state to not display all positions""" + cr, uid = self.cr, self.uid + ctx = {'search_show_all_positions': False} + partner_ids = self.partner.search(cr, uid, [], context=ctx) + partner_ids.sort() + self.assertTrue(self.bob_job1_id not in partner_ids) + self.assertTrue(self.roger_job2_id not in partner_ids) + + def test_01_show_all_positions(self): + """Check that all contact are show if context is empty or explicitly state to display all positions""" + cr, uid = self.cr, self.uid + + partner_ids = self.partner.search(cr, uid, [], context=None) + self.assertTrue(self.bob_job1_id in partner_ids) + self.assertTrue(self.roger_job2_id in partner_ids) + + ctx = {'search_show_all_positions': True} + partner_ids = self.partner.search(cr, uid, [], context=ctx) + self.assertTrue(self.bob_job1_id in partner_ids) + self.assertTrue(self.roger_job2_id in partner_ids) + + def test_02_reading_other_contact_one2many_show_all_positions(self): + """Check that readonly partner's ``other_contact_ids`` return all values whatever the context""" + cr, uid = self.cr, self.uid + + def read_other_contacts(pid, context=None): + return self.partner.read(cr, uid, [pid], ['other_contact_ids'], context=context)[0]['other_contact_ids'] + + def read_contacts(pid, context=None): + return self.partner.read(cr, uid, [pid], ['child_ids'], context=context)[0]['child_ids'] + + ctx = None + self.assertEqual(read_other_contacts(self.bob_contact_id, context=ctx), [self.bob_job1_id]) + ctx = {'search_show_all_positions': False} + self.assertEqual(read_other_contacts(self.bob_contact_id, context=ctx), [self.bob_job1_id]) + ctx = {'search_show_all_positions': True} + self.assertEqual(read_other_contacts(self.bob_contact_id, context=ctx), [self.bob_job1_id]) + + ctx = None + self.assertTrue(self.bob_job1_id in read_contacts(self.main_partner_id, context=ctx)) + ctx = {'search_show_all_positions': False} + self.assertTrue(self.bob_job1_id in read_contacts(self.main_partner_id, context=ctx)) + ctx = {'search_show_all_positions': True} + self.assertTrue(self.bob_job1_id in read_contacts(self.main_partner_id, context=ctx)) + + def test_03_search_match_attached_contacts(self): + """Check that searching partner also return partners having attached contacts matching search criteria""" + cr, uid = self.cr, self.uid + # Bob's contact has one other position which is related to 'Your Company' + # so search for all contacts working for 'Your Company' should contain bob position. + partner_ids = self.partner.search(cr, uid, [('parent_id', 'ilike', 'Your Company')], context=None) + self.assertTrue(self.bob_job1_id in partner_ids) + + # but when searching without 'all positions', we should get the position standalone contact instead. + ctx = {'search_show_all_positions': False} + partner_ids = self.partner.search(cr, uid, [('parent_id', 'ilike', 'Your Company')], context=ctx) + self.assertTrue(self.bob_contact_id in partner_ids) From 89c7a9fc3ef943b8e9654ab9bff0c05a950123fb Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Wed, 23 Oct 2013 13:27:48 +0200 Subject: [PATCH 2/5] [FIX] base_contact: fix contact staying attached after settings it's type to standalone --- base_contact/base_contact.py | 12 +++++++++--- base_contact/base_contact_view.xml | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/base_contact/base_contact.py b/base_contact/base_contact.py index cb4b79439..038336d5d 100644 --- a/base_contact/base_contact.py +++ b/base_contact/base_contact.py @@ -110,10 +110,16 @@ class res_partner(osv.osv): return result def onchange_contact_id(self, cr, uid, ids, contact_id, context=None): + values = {} if contact_id: - name = self.browse(cr, uid, contact_id, context=context).name - return {'value': {'name': name}} - return {} + values['name'] = self.browse(cr, uid, contact_id, context=context).name + return {'value': values} + + def onchange_contact_type(self, cr, uid, ids, contact_type, context=None): + values = {} + if contact_type == 'standalone': + values['contact_id'] = False + return {'value': values} class ir_actions_window(osv.osv): diff --git a/base_contact/base_contact_view.xml b/base_contact/base_contact_view.xml index 93eeac5aa..29080f270 100644 --- a/base_contact/base_contact_view.xml +++ b/base_contact/base_contact_view.xml @@ -153,7 +153,8 @@

    - To see personal information about this contact, please go to to the his person form: + To see personal information about this contact, please go to to the his person form:

    @@ -162,7 +163,7 @@
    - + Date: Wed, 23 Oct 2013 14:58:21 +0200 Subject: [PATCH 3/5] [FIX] base_contact: missing .name --- base_contact/base_contact.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_contact/base_contact.py b/base_contact/base_contact.py index 038336d5d..2201f3be6 100644 --- a/base_contact/base_contact.py +++ b/base_contact/base_contact.py @@ -84,7 +84,7 @@ class res_partner(osv.osv): def create(self, cr, user, vals, context=None): context = self._basecontact_check_context(cr, user, 'create', context) if not vals.get('name') and vals.get('contact_id'): - vals['name'] = self.browse(cr, user, vals['contact_id'], context=context) + vals['name'] = self.browse(cr, user, vals['contact_id'], context=context).name return super(res_partner, self).create(cr, user, vals, context=context) def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): From 4bb830013e7f04254effbdf06ab664190988606d Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Wed, 23 Oct 2013 15:03:14 +0200 Subject: [PATCH 4/5] [IMP] base_contact: add contact fields (name + title) sync between partner attached to the same contact --- base_contact/base_contact.py | 41 +++++++++++++++++++++++++ base_contact/tests/test_base_contact.py | 35 +++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/base_contact/base_contact.py b/base_contact/base_contact.py index 2201f3be6..e3ebcb299 100644 --- a/base_contact/base_contact.py +++ b/base_contact/base_contact.py @@ -109,6 +109,47 @@ class res_partner(osv.osv): result[partner.id] = partner.contact_id.id return result + def _contact_fields(self, cr, uid, context=None): + """ Returns the list of contact fields that are synced from the parent + when a partner is attached to him. """ + return ['name', 'title'] + + def _contact_sync_from_parent(self, cr, uid, partner, context=None): + """ Handle sync of contact fields when a new parent contact entity is set, + as if they were related fields """ + if partner.contact_id: + contact_fields = self._contact_fields(cr, uid, context=context) + sync_vals = self._update_fields_values(cr, uid, partner.contact_id, + contact_fields, context=context) + partner.write(sync_vals) + + def update_contact(self, cr, uid, ids, vals, context=None): + if context is None: + context = {} + if context.get('__update_contact_lock'): + return + contact_fields = self._contact_fields(cr, uid, context=context) + contact_vals = dict((field, vals[field]) for field in contact_fields if field in vals) + if contact_vals: + ctx = dict(context, __update_contact_lock=True) + self.write(cr, uid, ids, contact_vals, context=ctx) + + def _fields_sync(self, cr, uid, partner, update_values, context=None): + """ Sync commercial fields and address fields from company and to children, + contact fields from contact and to attached contact after create/update, + just as if those were all modeled as fields.related to the parent """ + super(res_partner, self)._fields_sync(cr, uid, partner, update_values, context=context) + contact_fields = self._contact_fields(cr, uid, context=context) + # 1. From UPSTREAM: sync from parent contact + if update_values.get('contact_id'): + self._contact_sync_from_parent(cr, uid, partner, context=context) + # 2. To DOWNSTREAM: sync contact fields to parent or related + elif any(field in contact_fields for field in update_values): + update_ids = [c.id for c in partner.other_contact_ids if not c.is_company] + if partner.contact_id: + update_ids.append(partner.contact_id.id) + self.update_contact(cr, uid, update_ids, update_values, context=context) + def onchange_contact_id(self, cr, uid, ids, contact_id, context=None): values = {} if contact_id: diff --git a/base_contact/tests/test_base_contact.py b/base_contact/tests/test_base_contact.py index 0f29a5dc0..a0cb3ba99 100644 --- a/base_contact/tests/test_base_contact.py +++ b/base_contact/tests/test_base_contact.py @@ -99,3 +99,38 @@ class Test_Base_Contact(common.TransactionCase): ctx = {'search_show_all_positions': False} partner_ids = self.partner.search(cr, uid, [('parent_id', 'ilike', 'Your Company')], context=ctx) self.assertTrue(self.bob_contact_id in partner_ids) + + def test_04_contact_creation(self): + """Check that we're begin to create a contact""" + cr, uid = self.cr, self.uid + + # Create a contact using only name + new_contact_id = self.partner.create(cr, uid, {'name': 'Bob Egnops'}) + self.assertEqual(self.partner.browse(cr, uid, new_contact_id).contact_type, 'standalone') + + # Create a contact with only contact_id + new_contact_id = self.partner.create(cr, uid, {'contact_id': self.bob_contact_id}) + new_contact = self.partner.browse(cr, uid, new_contact_id) + self.assertEqual(new_contact.name, 'Bob Egnops') + self.assertEqual(new_contact.contact_type, 'attached') + + # Create a contact with both contact_id and name; + # contact's name should override provided value in that case + new_contact_id = self.partner.create(cr, uid, {'contact_id': self.bob_contact_id, 'name': 'Rob Egnops'}) + self.assertEqual(self.partner.browse(cr, uid, new_contact_id).name, 'Bob Egnops') + + # Reset contact to standalone + self.partner.write(cr, uid, [new_contact_id], {'contact_id': False}) + self.assertEqual(self.partner.browse(cr, uid, new_contact_id).contact_type, 'standalone') + + def test_05_contact_fields_sync(self): + """Check that contact's fields are correctly synced between parent contact or related contacts""" + cr, uid = self.cr, self.uid + + # Test DOWNSTREAM sync + self.partner.write(cr, uid, [self.bob_contact_id], {'name': 'Rob Egnops'}) + self.assertEqual(self.partner.browse(cr, uid, self.bob_job1_id).name, 'Rob Egnops') + + # Test UPSTREAM sync + self.partner.write(cr, uid, [self.bob_job1_id], {'name': 'Bob Egnops'}) + self.assertEqual(self.partner.browse(cr, uid, self.bob_contact_id).name, 'Bob Egnops') From de8195744ea42ba8e2d9786c5f7322b08577971b Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Wed, 29 Jan 2014 18:09:07 -0500 Subject: [PATCH 5/5] [FIX] PEP8, 7.0 ORM imports --- base_contact/__init__.py | 3 +-- base_contact/__openerp__.py | 22 +++++++++++++--------- base_contact/base_contact.py | 25 +++++++++++++------------ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/base_contact/__init__.py b/base_contact/__init__.py index a93921487..c68500207 100644 --- a/base_contact/__init__.py +++ b/base_contact/__init__.py @@ -19,5 +19,4 @@ # ############################################################################## -import base_contact - +from . import base_contact diff --git a/base_contact/__openerp__.py b/base_contact/__openerp__.py index f53174dbe..3ca0e9ab4 100644 --- a/base_contact/__openerp__.py +++ b/base_contact/__openerp__.py @@ -22,6 +22,8 @@ { 'name': 'Contacts Management', 'version': '1.0', + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', 'category': 'Customer Relationship Management', 'complexity': "expert", 'description': """ @@ -32,21 +34,23 @@ It lets you define groups of contacts sharing some common information, like: * Birthdate * Nationality * Native Language - - """, - 'author': 'OpenERP SA', - 'website': 'http://www.openerp.com', - 'depends': ['base', 'process', 'contacts'], - 'init_xml': [], - 'update_xml': [ +""", + 'depends': [ + 'base', + 'process', + 'contacts' + ], + 'external_dependencies': {}, + 'data': [ 'base_contact_view.xml', ], - 'demo_xml': [ + 'demo': [ 'base_contact_demo.xml', ], + 'test': [], 'installable': True, 'auto_install': False, - #'certificate': '0031287885469', 'images': [], } + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_contact/base_contact.py b/base_contact/base_contact.py index e3ebcb299..aef6c460d 100644 --- a/base_contact/base_contact.py +++ b/base_contact/base_contact.py @@ -19,10 +19,10 @@ # ############################################################################## -from openerp.osv import fields, osv, expression +from openerp.osv import fields, orm, expression -class res_partner(osv.osv): +class res_partner(orm.Model): _inherit = 'res.partner' _contact_type = [ @@ -41,11 +41,12 @@ class res_partner(osv.osv): 'contact_type': fields.function(_get_contact_type, type='selection', selection=_contact_type, string='Contact Type', required=True, select=1, store=True), 'contact_id': fields.many2one('res.partner', 'Main Contact', - domain=[('is_company','=',False),('contact_type','=','standalone')]), + domain=[('is_company', '=', False), ('contact_type', '=', 'standalone')]), 'other_contact_ids': fields.one2many('res.partner', 'contact_id', 'Others Positions'), # Person specific fields - 'birthdate_date': fields.date('Birthdate'), # add a 'birthdate' as date field, i.e different from char 'birthdate' introduced v6.1! + # add a 'birthdate' as date field, i.e different from char 'birthdate' introduced v6.1! + 'birthdate_date': fields.date('Birthdate'), 'nationality_id': fields.many2one('res.country', 'Nationality'), } @@ -54,22 +55,22 @@ class res_partner(osv.osv): } def _basecontact_check_context(self, cr, user, mode, context=None): + """ Remove 'search_show_all_positions' for non-search mode. + Keeping it in context can result in unexpected behaviour (ex: reading + one2many might return wrong result - i.e with "attached contact" removed + even if it's directly linked to a company). """ if context is None: context = {} - # Remove 'search_show_all_positions' for non-search mode. - # Keeping it in context can result in unexpected behaviour (ex: reading - # one2many might return wrong result - i.e with "attached contact" removed - # even if it's directly linked to a company). if mode != 'search': context.pop('search_show_all_positions', None) return context def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False): + """ Display only standalone contact matching ``args`` or having + attached contact matching ``args`` """ if context is None: context = {} if context.get('search_show_all_positions') is False: - # display only standalone contact matching ``args`` or having - # attached contact matching ``args`` args = expression.normalize_domain(args) attached_contact_args = expression.AND((args, [('contact_type', '=', 'attached')])) attached_contact_ids = super(res_partner, self).search(cr, user, attached_contact_args, @@ -163,7 +164,7 @@ class res_partner(osv.osv): return {'value': values} -class ir_actions_window(osv.osv): +class ir_actions_window(orm.Model): _inherit = 'ir.actions.act_window' def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): @@ -177,7 +178,7 @@ class ir_actions_window(osv.osv): action_context = action.get('context', '{}') or '{}' if 'search_show_all_positions' not in action_context: action['context'] = action_context.replace('{', - "{'search_show_all_positions': False,", 1) + "{'search_show_all_positions': False,", 1) if isinstance(ids, (int, long)): if actions: return actions[0]