Browse Source

[ADD] base_contact_function_partner_firstname

Add firstname before name.
Name is considered like the lastname and we have firstname and lastname on
partner view and contact view.
pull/20/head
EL HADJI DEM 11 years ago
committed by Sandy Carter
parent
commit
2b0ef42363
  1. 23
      base_contact_function_partner_firstname/__init__.py
  2. 51
      base_contact_function_partner_firstname/__openerp__.py
  3. 27
      base_contact_function_partner_firstname/i18n/base_contact_function_partner_firstname.pot
  4. 27
      base_contact_function_partner_firstname/i18n/fr.po
  5. 82
      base_contact_function_partner_firstname/res_partner.py
  6. 76
      base_contact_function_partner_firstname/res_partner_view.xml
  7. 27
      base_contact_function_partner_firstname/tests/__init__.py
  8. 57
      base_contact_function_partner_firstname/tests/test_partner.py

23
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
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import res_partner

51
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
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}

27
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 <elhadji.dem@savoirfairelinux.com>\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 ""

27
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 <elhadji.dem@savoirfairelinux.com>\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"

82
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
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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
)

76
base_contact_function_partner_firstname/res_partner_view.xml

@ -0,0 +1,76 @@
<?xml version = "1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Redefine this part of view from firstname_partner module -->
<record id="view_partner_form_firstname_inherit11" model="ir.ui.view">
<field name="name">res.partner.form.firstname.inherit11</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_firstname.view_partner_form_firstname"/>
<field name="arch" type="xml">
<!--Redefine firstname field in view partner-->
<field name="firstname" position="replace">
<group attrs="{'invisible': [('is_company', '=', True)]}">
<field name="firstname"/>
</group>
</field>
<!--Redefine firstname field in contact view-->
<xpath expr="//form[@string='Contact']/sheet/div//field[@name='firstname']" position="replace">
<field name="firstname" attrs="{'invisible': [('contact_type', '=', 'attached')]}"/>
</xpath>
</field>
</record>
<!--Replace name by full name in kanban view-->
<record id="view_partner_form_firstname_inherit11" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base_contact_function.view_contact_by_function_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='other_contact_history_ids']/kanban//field[@name='name']" position="replace">
<field name="lastname"/>
</xpath>
<xpath expr="//field[@name='other_contact_history_ids']/kanban/templates//t[@t-name='kanban-box']//div[@class='oe_kanban_details']//field[@name='name']"
position="before">
<field name="firstname"/>
</xpath>
<!--Display firstname and name after Image-->
<xpath expr="//field[@name='other_contact_history_ids']/form[@string='Contact']/sheet//field[@name='image']"
position="after">
<h1>
<field name="contact_id" style="width: 70%%" readonly="1"/>
</h1>
</xpath>
</field>
</record>
<!--Display firstname and name in kanban view for other position -->
<record id="view_partner_form_firstname_name" model="ir.ui.view">
<field name="name">res.partner.form.firstname.name</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base_contact_function.view_position_info_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='name']"
position="replace"/>
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='image']"
position="after">
<h1>
<field name="contact_id" style="width: 70%%" readonly="1"/>
</h1>
</xpath>
<!-- Don't display the label field -->
<xpath expr="//field[@name='other_contact_ids']/form//label[@for='name']"
position="replace"/>
<!-- Add firstname before name in templates view -->
<xpath expr="//t[@t-name='kanban-box']//div[@class='oe_kanban_details']/h4[@class='oe_partner_heading']//field[@name='name']"
position="before">
<field name="firstname"/>
</xpath>
</field>
</record>
</data>
</openerp>

27
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
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_partner
checks = [
test_partner,
]

57
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
# (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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')
Loading…
Cancel
Save