diff --git a/base_contact_function_partner_firstname/__init__.py b/base_contact_function_partner_firstname/__init__.py new file mode 100644 index 000000000..ecc058c07 --- /dev/null +++ b/base_contact_function_partner_firstname/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Savoir-faire Linux +# (). +# +# 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 res_partner diff --git a/base_contact_function_partner_firstname/__openerp__.py b/base_contact_function_partner_firstname/__openerp__.py new file mode 100644 index 000000000..556bc289d --- /dev/null +++ b/base_contact_function_partner_firstname/__openerp__.py @@ -0,0 +1,51 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Savoir-faire Linux +# (). +# +# 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 by Functions - Partner Firstname Bindings', + 'version': '0.1', + 'category': 'Customer Relationship Management', + 'summary': 'Contacts by Functions - Partner Firstname Bindings', + 'description': """ +Contacts by Functions - Partner Firstname Bindings +================================================== + +Contributors +------------ +* El Hadji Dem (elhadji.dem@savoirfairelinux.com) +""", + 'author': 'Savoir-faire Linux', + 'website': 'www.savoirfairelinux.com', + 'license': 'AGPL-3', + 'depends': [ + 'base_contact_function', + 'partner_firstname', + ], + 'data': [ + 'res_partner_view.xml', + ], + 'test': [], + 'demo': [ + ], + 'installable': True, + 'auto_install': True, +} diff --git a/base_contact_function_partner_firstname/i18n/base_contact_function_partner_firstname.pot b/base_contact_function_partner_firstname/i18n/base_contact_function_partner_firstname.pot new file mode 100644 index 000000000..51f236232 --- /dev/null +++ b/base_contact_function_partner_firstname/i18n/base_contact_function_partner_firstname.pot @@ -0,0 +1,27 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_contact_function_partner_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-01-03 07:16+0000\n" +"PO-Revision-Date: 2014-01-03 02:17-0500\n" +"Last-Translator: EL Hadji DEM \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.5.4\n" + +#. module: base_contact_function_partner_firstname +#: view:res.partner:0 +msgid "lastname" +msgstr "" + +#. module: base_contact_function_partner_firstname +#: view:res.partner:0 +msgid "Firstname" +msgstr "" diff --git a/base_contact_function_partner_firstname/i18n/fr.po b/base_contact_function_partner_firstname/i18n/fr.po new file mode 100644 index 000000000..a9db9e575 --- /dev/null +++ b/base_contact_function_partner_firstname/i18n/fr.po @@ -0,0 +1,27 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_contact_function_partner_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-01-03 07:17+0000\n" +"PO-Revision-Date: 2014-01-03 02:18-0500\n" +"Last-Translator: EL Hadji DEM \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.5.4\n" + +#. module: base_contact_function_partner_firstname +#: view:res.partner:0 +msgid "lastname" +msgstr "Nom" + +#. module: base_contact_function_partner_firstname +#: view:res.partner:0 +msgid "Firstname" +msgstr "Prénom" diff --git a/base_contact_function_partner_firstname/res_partner.py b/base_contact_function_partner_firstname/res_partner.py new file mode 100644 index 000000000..d6dc9a460 --- /dev/null +++ b/base_contact_function_partner_firstname/res_partner.py @@ -0,0 +1,82 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Savoir-faire Linux +# (). +# +# 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 time +from openerp.osv import orm + + +class res_partner(orm.Model): + _inherit = 'res.partner' + + 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).name + if vals.get('end_date'): + if vals.get('end_date', "Z") <= time.strftime('%Y-%m-%d'): + vals['active'] = False + if vals.get('contact_type') == 'standalone': + contact_vals = dict( + filter(lambda (k, v): k != 'parent_id', vals.iteritems()) + ) + contact_vals['active'] = True + contact_vals['function_id'] = None + vals['contact_id'] = super(res_partner, self).create( + cr, user, contact_vals, context=context + ) + self.write(cr, user, vals['contact_id'], { + 'firstname': vals.get('firstname', ''), + 'lastname': vals.get('lastname', ''), + }, context=context) + # Check if we create existing contact from company(ie: company is true) + # Check if we create another function from contact view + if vals.get('contact_type') == 'attached' or ( + not vals.get('contact_type') and vals.get('contact_id')): + contact_info = self.browse( + cr, user, vals.get('contact_id'), context=context) + vals['firstname'] = contact_info.firstname + vals['title'] = contact_info.title.id or '' + + if ('contact_id'in vals and ('reset_password' in context or + 'install_mode' in context)): + return vals['contact_id'] + res = super(res_partner, self).create(cr, user, vals, context=context) + return res + + def write(self, cr, user, ids, vals, context=None): + context = self._basecontact_check_context(cr, user, 'write', context) + if vals.get('end_date'): + if vals.get('end_date', "Z") <= time.strftime('%Y-%m-%d'): + vals['active'] = False + if vals.get('contact_type') == 'standalone': + contact_vals = dict( + filter(lambda (k, v): k != 'parent_id', vals.iteritems()) + ) + contact_vals['active'] = True + contact_vals['function_id'] = None + vals['contact_id'] = super(res_partner, self).write( + cr, user, contact_vals, context=context + ) + return super(res_partner, self).write( + cr, user, ids, vals, context=context + ) diff --git a/base_contact_function_partner_firstname/res_partner_view.xml b/base_contact_function_partner_firstname/res_partner_view.xml new file mode 100644 index 000000000..b92aeee6b --- /dev/null +++ b/base_contact_function_partner_firstname/res_partner_view.xml @@ -0,0 +1,76 @@ + + + + + + + res.partner.form.firstname.inherit11 + res.partner + + + + + + + + + + + + + + + + + + res.partner + + + + + + + + + + +

+ +

+
+
+
+ + + + res.partner.form.firstname.name + res.partner + + + + + + +

+ +

+
+ + + + + + + + + +
+
+
+
diff --git a/base_contact_function_partner_firstname/tests/__init__.py b/base_contact_function_partner_firstname/tests/__init__.py new file mode 100644 index 000000000..99fe1a426 --- /dev/null +++ b/base_contact_function_partner_firstname/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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_partner + +checks = [ + test_partner, +] diff --git a/base_contact_function_partner_firstname/tests/test_partner.py b/base_contact_function_partner_firstname/tests/test_partner.py new file mode 100644 index 000000000..24d49ee95 --- /dev/null +++ b/base_contact_function_partner_firstname/tests/test_partner.py @@ -0,0 +1,57 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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.common import TransactionCase + + +class test_partner_contact_id(TransactionCase): + + def setUp(self): + super(test_partner_contact_id, self).setUp() + # Clean up registries + self.registry('ir.model').clear_caches() + self.registry('ir.model.data').clear_caches() + # Get registries + self.user_model = self.registry("res.users") + self.partner_model = self.registry("res.partner") + # Get context + self.context = self.user_model.context_get(self.cr, self.uid) + # Create values for test, contact also created + contact_id = self.partner_model.create(self.cr, self.uid, { + 'name': u'Astérix', + 'title': 1, + }, context=self.context) + self.vals = { + 'name': u'Obélix', + 'type': 'contact', + 'contact_id': contact_id, + } + + def test_create_partner(self): + cr, uid, vals, context = self.cr, self.uid, self.vals, self.context + partner_id = self.partner_model.create(cr, uid, vals, context=context) + partner = self.partner_model.browse( + cr, uid, partner_id, context=context + ) + # Creating the partner uses the name from the contact + self.assertEqual(partner.name, u'Astérix') + self.assertEqual(partner.lastname, u'Astérix')