Merge lp:~savoirfairelinux-openerp/partner-contact-management/firstname_lastname_fix_bug_email into lp:~savoirfairelinux-openerp/partner-contact-management/base_contact_by_functions

Status: Merged
Merged at revision: 36
Proposed branch: lp:~savoirfairelinux-openerp/partner-contact-management/firstname_lastname_fix_bug_email
Merge into: lp:~savoirfairelinux-openerp/partner-contact-management/base_contact_by_functions
Diff against target: 908 lines (+505/-259)
19 files modified
base_continent/__init__.py (+24/-0)
base_continent/__openerp__.py (+42/-0)
base_continent/base_continent.py (+34/-0)
base_continent/base_continent_data.xml (+27/-0)
base_continent/base_continent_view.xml (+73/-0)
base_continent/country.py (+30/-0)
base_continent/i18n/base_continent.po (+56/-0)
base_continent/i18n/fr.po (+56/-0)
base_continent/partner.py (+34/-0)
base_continent/security/ir.model.access.csv (+3/-0)
firstname_display_name_trigger/__init__.py (+0/-24)
firstname_display_name_trigger/__openerp__.py (+0/-41)
firstname_display_name_trigger/res_partner.py (+0/-65)
firstname_display_name_trigger/tests/__init__.py (+0/-5)
firstname_display_name_trigger/tests/test_display_name.py (+0/-31)
partner_firstname/__openerp__.py (+26/-16)
partner_firstname/partner.py (+58/-39)
partner_firstname/partner_view.xml (+36/-33)
partner_firstname/res_user.py (+6/-5)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/partner-contact-management/firstname_lastname_fix_bug_email
Reviewer Review Type Date Requested Status
Sandy Carter (http://www.savoirfairelinux.com) Pending
Review via email: mp+202772@code.launchpad.net

Description of the change

[IMP] merge with https://code.launchpad.net/~savoirfairelinux-openerp/partner-contact-management/partner_firstname_lastname.It adds base_continent module;
- replace lastname by name, add full (=firstname + name).
- remove firstname_display_name_trigger because it is redundant;
- is_company field from contact view: this field also exists in partner view;it is redundant
- Redefine user class.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'base_continent'
=== added file 'base_continent/__init__.py'
--- base_continent/__init__.py 1970-01-01 00:00:00 +0000
+++ base_continent/__init__.py 2014-01-22 23:37:10 +0000
@@ -0,0 +1,24 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import base_continent
23from . import country
24from . import partner
025
=== added file 'base_continent/__openerp__.py'
--- base_continent/__openerp__.py 1970-01-01 00:00:00 +0000
+++ base_continent/__openerp__.py 2014-01-22 23:37:10 +0000
@@ -0,0 +1,42 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22
23{
24 'name': 'Continent management',
25 'version': '1.0',
26 'depends': ['base'],
27 'author': 'Camptocamp',
28 'license': 'AGPL-3',
29 'description': """
30This module introduces continent management.
31============================================
32Links continents to countries,
33adds continent field on partner form
34""",
35 'category': 'Generic Modules/Base',
36 'data': [
37 'base_continent_view.xml',
38 'base_continent_data.xml',
39 'security/ir.model.access.csv'],
40 'active': False,
41 'installable': True,
42}
043
=== added file 'base_continent/base_continent.py'
--- base_continent/base_continent.py 1970-01-01 00:00:00 +0000
+++ base_continent/base_continent.py 2014-01-22 23:37:10 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv.orm import Model
23from openerp.osv import fields
24
25
26class Continent(Model):
27 _name = 'res.continent'
28 _description = 'Continent'
29 _columns = {
30 'name': fields.char('Continent Name', size=64,
31 help='The full name of the continent.',
32 required=True, translate=True),
33 }
34 _order = 'name'
035
=== added file 'base_continent/base_continent_data.xml'
--- base_continent/base_continent_data.xml 1970-01-01 00:00:00 +0000
+++ base_continent/base_continent_data.xml 2014-01-22 23:37:10 +0000
@@ -0,0 +1,27 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data noupdate="1">
4
5 <record id="af" model="res.continent">
6 <field name="name">Africa</field>
7 </record>
8 <record id="an" model="res.continent">
9 <field name="name">Antarctica</field>
10 </record>
11 <record id="as" model="res.continent">
12 <field name="name">Asia</field>
13 </record>
14 <record id="eu" model="res.continent">
15 <field name="name">Europe</field>
16 </record>
17 <record id="na" model="res.continent">
18 <field name="name">North America</field>
19 </record>
20 <record id="oc" model="res.continent">
21 <field name="name">Oceania</field>
22 </record>
23 <record id="sa" model="res.continent">
24 <field name="name">South America</field>
25 </record>
26 </data>
27</openerp>
028
=== added file 'base_continent/base_continent_view.xml'
--- base_continent/base_continent_view.xml 1970-01-01 00:00:00 +0000
+++ base_continent/base_continent_view.xml 2014-01-22 23:37:10 +0000
@@ -0,0 +1,73 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <!-- add continent to res country tree -->
5 <record model="ir.ui.view" id="view_country_tree_add_continent">
6 <field name="name">res.country.tree.add_continent</field>
7 <field name="model">res.country</field>
8 <field name="inherit_id" ref="base.view_country_tree" />
9 <field name="arch" type="xml">
10 <field name="code" position="after">
11 <field name="continent_id"/>
12 </field>
13 </field>
14 </record>
15
16 <!-- add continent to res country form -->
17 <record model="ir.ui.view" id="view_country_form_add_continent">
18 <field name="name">res.country.form.add_continent</field>
19 <field name="model">res.country</field>
20 <field name="inherit_id" ref="base.view_country_form"/>
21 <field name="arch" type="xml">
22 <field name="code" position="after">
23 <field name="continent_id"/>
24 </field>
25 </field>
26 </record>
27
28 <record id="view_continent_tree" model="ir.ui.view">
29 <field name="name">res.continent.tree</field>
30 <field name="model">res.continent</field>
31 <field name="arch" type="xml">
32 <tree string="Continent">
33 <field name="name"/>
34 </tree>
35 </field>
36 </record>
37
38 <record id="view_continent_form" model="ir.ui.view">
39 <field name="name">res.continent.form</field>
40 <field name="model">res.continent</field>
41 <field name="arch" type="xml">
42 <form string="Continent" version="7.0">
43 <group>
44 <field name="name"/>
45 </group>
46 </form>
47 </field>
48 </record>
49
50 <record id="action_continent" model="ir.actions.act_window">
51 <field name="name">Continents</field>
52 <field name="type">ir.actions.act_window</field>
53 <field name="res_model">res.continent</field>
54 <field name="view_type">form</field>
55 <field name="help">Display and manage the list of all continents that can be assigned to your partner records.</field>
56 </record>
57
58 <menuitem action="action_continent" id="menu_continent_partner" parent="base.menu_localisation" sequence="1" groups="base.group_no_one"/>
59
60 <!-- add continent to res partner form -->
61 <record model="ir.ui.view" id="res_partner_form_add_continent">
62 <field name="name">res.partner.form.add_continent</field>
63 <field name="model">res.partner</field>
64 <field name="inherit_id" ref="base.view_partner_form"/>
65 <field name="arch" type="xml">
66 <field name="country_id" position="after">
67 <field name="continent_id" widget="selection"/>
68 </field>
69 </field>
70 </record>
71
72 </data>
73</openerp>
074
=== added file 'base_continent/country.py'
--- base_continent/country.py 1970-01-01 00:00:00 +0000
+++ base_continent/country.py 2014-01-22 23:37:10 +0000
@@ -0,0 +1,30 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv.orm import Model
23from openerp.osv import fields
24
25
26class Country(Model):
27 _inherit = 'res.country'
28 _columns = {
29 'continent_id': fields.many2one('res.continent', 'Continent'),
30 }
031
=== added directory 'base_continent/i18n'
=== added file 'base_continent/i18n/base_continent.po'
--- base_continent/i18n/base_continent.po 1970-01-01 00:00:00 +0000
+++ base_continent/i18n/base_continent.po 2014-01-22 23:37:10 +0000
@@ -0,0 +1,56 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * base_continent
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-01-14 15:19+0000\n"
10"PO-Revision-Date: 2014-01-14 15:19+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: base_continent
19#: model:ir.actions.act_window,help:base_continent.action_continent
20msgid "Display and manage the list of all continents that can be assigned to your partner records."
21msgstr ""
22
23#. module: base_continent
24#: model:ir.actions.act_window,name:base_continent.action_continent
25#: model:ir.ui.menu,name:base_continent.menu_continent_partner
26msgid "Continents"
27msgstr ""
28
29#. module: base_continent
30#: model:ir.model,name:base_continent.model_res_country
31msgid "Country"
32msgstr ""
33
34#. module: base_continent
35#: help:res.continent,name:0
36msgid "The full name of the continent."
37msgstr ""
38
39#. module: base_continent
40#: field:res.continent,name:0
41msgid "Continent Name"
42msgstr ""
43
44#. module: base_continent
45#: model:ir.model,name:base_continent.model_res_partner
46msgid "Partner"
47msgstr ""
48
49#. module: base_continent
50#: model:ir.model,name:base_continent.model_res_continent
51#: view:res.continent:0
52#: field:res.country,continent_id:0
53#: field:res.partner,continent_id:0
54msgid "Continent"
55msgstr ""
56
057
=== added file 'base_continent/i18n/fr.po'
--- base_continent/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ base_continent/i18n/fr.po 2014-01-22 23:37:10 +0000
@@ -0,0 +1,56 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * base_continent
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-01-14 15:19+0000\n"
10"PO-Revision-Date: 2014-01-14 15:19+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: base_continent
19#: model:ir.actions.act_window,help:base_continent.action_continent
20msgid "Display and manage the list of all continents that can be assigned to your partner records."
21msgstr "Affiche et gère la liste de tous les continents qui peuvent être associés à vos partenaires."
22
23#. module: base_continent
24#: model:ir.actions.act_window,name:base_continent.action_continent
25#: model:ir.ui.menu,name:base_continent.menu_continent_partner
26msgid "Continents"
27msgstr "Continents"
28
29#. module: base_continent
30#: model:ir.model,name:base_continent.model_res_country
31msgid "Country"
32msgstr "Pays"
33
34#. module: base_continent
35#: help:res.continent,name:0
36msgid "The full name of the continent."
37msgstr "Le nom complet du continent."
38
39#. module: base_continent
40#: field:res.continent,name:0
41msgid "Continent Name"
42msgstr "Nom du continent"
43
44#. module: base_continent
45#: model:ir.model,name:base_continent.model_res_partner
46msgid "Partner"
47msgstr "Partenaire"
48
49#. module: base_continent
50#: model:ir.model,name:base_continent.model_res_continent
51#: view:res.continent:0
52#: field:res.country,continent_id:0
53#: field:res.partner,continent_id:0
54msgid "Continent"
55msgstr "Continent"
56
057
=== added file 'base_continent/partner.py'
--- base_continent/partner.py 1970-01-01 00:00:00 +0000
+++ base_continent/partner.py 2014-01-22 23:37:10 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv.orm import Model
23from openerp.osv import fields
24
25
26class Partner(Model):
27 _inherit = 'res.partner'
28 _columns = {
29 'continent_id': fields.related('country_id', 'continent_id',
30 type='many2one',
31 relation='res.continent',
32 string='Continent',
33 readonly=True, store=True),
34 }
035
=== added directory 'base_continent/security'
=== added file 'base_continent/security/ir.model.access.csv'
--- base_continent/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ base_continent/security/ir.model.access.csv 2014-01-22 23:37:10 +0000
@@ -0,0 +1,3 @@
1id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2access_res_continent_group_all,res_continent group_user_all,model_res_continent,,1,0,0,0
3access_res_continent_group_user,res_continent group_user,model_res_continent,base.group_partner_manager,1,1,1,1
04
=== removed directory 'firstname_display_name_trigger'
=== removed file 'firstname_display_name_trigger/__init__.py'
--- firstname_display_name_trigger/__init__.py 2013-05-23 12:13:51 +0000
+++ firstname_display_name_trigger/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Yannick Vaucher
5# Copyright 2013 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import res_partner
23
24# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
250
=== removed file 'firstname_display_name_trigger/__openerp__.py'
--- firstname_display_name_trigger/__openerp__.py 2013-06-18 08:44:56 +0000
+++ firstname_display_name_trigger/__openerp__.py 1970-01-01 00:00:00 +0000
@@ -1,41 +0,0 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Yannick Vaucher
5# Copyright 2013 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{'name': 'Link module if partner_lastname and account_report_company are installed',
22 'version': '1.0',
23 'author': 'Camptocamp',
24 'maintainer': 'Camptocamp',
25 'category': 'Hidden',
26 'complexity': 'normal', # easy, normal, expert
27 'depends': [
28 'account_report_company',
29 'partner_firstname',
30 ],
31 'description': """
32Adapt the computation of display name so that it gets visible in tree and kanban views.
33 """,
34 'website': 'http://www.camptocamp.com',
35 'data': [],
36 'installable': True,
37 'images': [],
38 'auto_install': True,
39 'license': 'AGPL-3',
40 'application': False}
41
420
=== removed file 'firstname_display_name_trigger/res_partner.py'
--- firstname_display_name_trigger/res_partner.py 2013-12-04 12:52:48 +0000
+++ firstname_display_name_trigger/res_partner.py 1970-01-01 00:00:00 +0000
@@ -1,65 +0,0 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Yannick Vaucher
5# Copyright 2013 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21from openerp.osv import orm, fields
22
23
24class ResPartner(orm.Model):
25 _inherit = 'res.partner'
26
27 def _display_name_compute(self, cr, uid, ids, name, args, context=None):
28 return dict(self.name_get(cr, uid, ids, context=context))
29
30 def name_get(self, cr, uid, ids, context=None):
31 """ By pass of name_get to use directly firstname and lastname
32 as we cannot ensure name as already been computed when calling this
33 method for display_name"""
34 if context is None:
35 context = {}
36 if isinstance(ids, (int, long)):
37 ids = [ids]
38 res = []
39 for record in self.browse(cr, uid, ids, context=context):
40 names = (record.lastname, record.firstname)
41 name = u" ".join([s for s in names if s])
42 if record.parent_id and not record.is_company:
43 name = "%s, %s" % (record.parent_id.name, name)
44 if context.get('show_address'):
45 name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
46 name = name.replace('\n\n','\n')
47 name = name.replace('\n\n','\n')
48 if context.get('show_email') and record.email:
49 name = "%s <%s>" % (name, record.email)
50 res.append((record.id, name))
51 return res
52
53
54 _display_name_store_triggers = {
55 'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)]),
56 ['parent_id', 'is_company', 'name', 'firstname', 'lastname'], 10)
57 }
58
59 # indirection to avoid passing a copy of the overridable method when declaring the function field
60 _display_name = lambda self, *args, **kwargs: self._display_name_compute(*args, **kwargs)
61
62 _columns = {
63 # extra field to allow ORDER BY to match visible names
64 'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers),
65 }
660
=== removed directory 'firstname_display_name_trigger/tests'
=== removed file 'firstname_display_name_trigger/tests/__init__.py'
--- firstname_display_name_trigger/tests/__init__.py 2013-05-24 11:39:16 +0000
+++ firstname_display_name_trigger/tests/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
1import test_display_name
2
3checks = [
4 test_display_name
5 ]
60
=== removed file 'firstname_display_name_trigger/tests/test_display_name.py'
--- firstname_display_name_trigger/tests/test_display_name.py 2013-05-24 11:39:16 +0000
+++ firstname_display_name_trigger/tests/test_display_name.py 1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
1import unittest2
2
3import openerp.tests.common as common
4
5class test_display_name(common.TransactionCase):
6
7 def setUp(self):
8 super(test_display_name,self).setUp()
9 cr, uid = self.cr, self.uid
10 self.res_partner = self.registry('res.partner')
11
12
13 def test_00_create_res_partner(self):
14 """ Test if the display name has been correctly set """
15 cr, uid = self.cr, self.uid
16 partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
17 partner_records = self.res_partner.browse(cr, uid, [partner_id])
18 p1 = partner_records[0]
19 self.assertEqual(p1.display_name, 'Lastname Firstname', 'Partner display_name incorect')
20
21 def test_01_res_partner_write_lastname(self):
22 """ Test if the display name has been correctly set """
23 cr, uid = self.cr, self.uid
24 partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
25 partner_records = self.res_partner.browse(cr, uid, [partner_id])
26 p1 = partner_records[0]
27 self.res_partner.write(cr, uid, partner_id, {'lastname': 'Last'})
28 self.assertEqual(p1.display_name, 'Last Firstname', 'Partner display_name incorect')
29
30if __name__ == '__main__':
31 unittest2.main()
320
=== modified file 'partner_firstname/__openerp__.py'
--- partner_firstname/__openerp__.py 2014-01-03 15:07:50 +0000
+++ partner_firstname/__openerp__.py 2014-01-22 23:37:10 +0000
@@ -18,23 +18,33 @@
18#18#
19##############################################################################19##############################################################################
2020
21{'name': 'Partner first name, last name',21{
22 'description': """Split first name and last name on res.partner.22 'name': 'Partner first name, last name',
23 'description': """
24Split first name and last name on res.partner.
25==============================================
2326
24The field 'name' becomes a stored function field concatenating lastname, firstname27The field 'name' becomes a stored function field concatenating lastname, firstname
28
29Contributeurs
30-------------
31* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
32* Camptocamp
25""",33""",
26 'version': '1.0.1',34 'version': '1.0.1',
27 'author': 'Camptocamp',35 'author': 'Camptocamp',
28 'category': 'MISC',36 'category': 'MISC',
29 'website': 'http://www.camptocamp.com',37 'website': 'http://www.camptocamp.com',
30 'depends': ['base'],38 'depends': ['base'],
31 'data': [39 'data': [
32 'partner_view.xml',40 'partner_view.xml',
33 'res_user_view.xml',41 'res_user_view.xml',
34 ],42 ],
35 'demo': [],43 'demo': [],
36 'test': [],44 'test': [],
37 'auto_install': False,45 'auto_install': False,
38 'installable': True,46 'installable': True,
39 'images': []47 'images': []
40}48}
49
50# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
4151
=== modified file 'partner_firstname/partner.py'
--- partner_firstname/partner.py 2013-08-12 06:18:39 +0000
+++ partner_firstname/partner.py 2014-01-22 23:37:10 +0000
@@ -17,49 +17,68 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#18#
19##############################################################################19##############################################################################
20from openerp.osv.orm import Model, fields20
2121from openerp.osv import orm, fields
2222
23class ResPartner(Model):23
24class res_partner(orm.Model):
24 """Adds lastname and firstname, name become a stored function field"""25 """Adds lastname and firstname, name become a stored function field"""
2526
26 _inherit = 'res.partner'27 _inherit = 'res.partner'
2728
28 def init(self, cursor):29 def _display_name_compute(self, cr, uid, ids, name, args, context=None):
29 cursor.execute('SELECT id FROM res_partner WHERE lastname IS NOT NULL Limit 1')30 return dict(self.name_get(cr, uid, ids, context=context))
30 if not cursor.fetchone():
31 cursor.execute('UPDATE res_partner set lastname = name WHERE name IS NOT NULL')
3231
33 def _compute_name_custom(self, cursor, uid, ids, fname, arg, context=None):32 def name_get(self, cr, uid, ids, context=None):
34 res = {}33 """ By pass of name_get to use directly firstname and lastname
35 partners = self.read(cursor, uid, ids,34 as we cannot ensure name as already been computed when calling this
36 ['firstname', 'lastname'], context=context)35 method for display_name"""
37 for rec in partners:36 if context is None:
38 names = (rec['lastname'], rec['firstname'])37 context = {}
39 fullname = " ".join([s for s in names if s])38 if isinstance(ids, (int, long)):
40 res[rec['id']] = fullname39 ids = [ids]
40 res = []
41 for record in self.browse(cr, uid, ids, context=context):
42 names = (record.firstname, record.name)
43 name = u" ".join([s for s in names if s])
44 if record.parent_id and not record.is_company:
45 name = "%s, %s" % (record.parent_id.name, name)
46 if context.get('show_address'):
47 name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
48 name = name.replace('\n\n', '\n')
49 name = name.replace('\n\n', '\n')
50 if context.get('show_email') and record.email:
51 name = "%s <%s>" % (name, record.email)
52 res.append((record.id, name))
41 return res53 return res
4254
43 def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):55 def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
44 return self.write(cursor, uid, partner_id,56 if args is None:
45 {'lastname': field_value}, context=context)57 args = []
4658 if context is None:
47 def create(self, cursor, uid, vals, context=None):59 context = {}
48 """To support data backward compatibility we have to keep this overwrite even if we60 if name:
49 use fnct_inv: otherwise we can't create entry because lastname is mandatory and module61 ids = self.search(cr, uid, [('full_name', operator, name)] + args, limit=limit, context=context)
50 will not install if there is demo data"""62 else:
51 to_use = vals63 ids = self.search(cr, uid, args, limit=limit, context=context or {})
52 if vals.get('name'):64 return self.name_get(cr, uid, ids, context=context)
53 corr_vals = vals.copy()65
54 corr_vals['lastname'] = corr_vals['name']66 def get_full_name(self, cr, uid, ids, field_name, arg, context=None):
55 del(corr_vals['name'])67 return dict(self.name_get(cr, uid, ids, context=context))
56 to_use = corr_vals68
57 return super(ResPartner, self).create(cursor, uid, to_use, context=context)69 _display_name_store_triggers = {
5870 'res.partner': (lambda self, cr, uid, ids, context=None: self.search(cr, uid, [('id', 'child_of', ids)]),
59 _columns = {'name': fields.function(_compute_name_custom, string="Name",71 ['parent_id', 'is_company', 'name', 'firstname'], 10)
60 type="char", store=True,72 }
61 select=True, readonly=True,73
62 fnct_inv=_write_name),74 # indirection to avoid passing a copy of the overridable method when declaring the function field
6375 _display_name = lambda self, *args, **kwargs: self._display_name_compute(*args, **kwargs)
64 'firstname': fields.char("Firstname"),76
65 'lastname': fields.char("Lastname", required=True)}77 _columns = {
78 'full_name': fields.function(_display_name, type='char',
79 string='Full name',
80 store=_display_name_store_triggers,
81 help="First name."),
82 'firstname': fields.char("First name", help="First name.")
83 }
84# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
6685
=== modified file 'partner_firstname/partner_view.xml'
--- partner_firstname/partner_view.xml 2013-11-13 16:18:13 +0000
+++ partner_firstname/partner_view.xml 2014-01-22 23:37:10 +0000
@@ -1,51 +1,54 @@
1<openerp>1<openerp>
2 <data>2 <data>
3 <record id="view_partner_simple_form_firstname" model="ir.ui.view">
4 <field name="name">res.partner.simplified.form.firstname</field>
5 <field name="model">res.partner</field>
6 <field name="inherit_id" ref="base.view_partner_simple_form"/>
7 <field name="arch" type="xml">
8 <field name="name" position="attributes">
9 <attribute name="attrs">{'readonly': [('is_company', '=', False)], 'required': [('is_company', '=', True)]}</attribute>
10 </field>
11 <field name="category_id" position="before">
12 <group attrs="{'invisible': [('is_company', '=', True)]}">
13 <field name="lastname" attrs="{'required': [('is_company', '=', False)]}"/>
14 <field name="firstname" />
15 </group>
16 </field>
17 </field>
18 </record>
193
20 <record id="view_partner_form_firstname" model="ir.ui.view">4 <record id="view_partner_form_firstname" model="ir.ui.view">
21 <field name="name">res.partner.form.firstname</field>5 <field name="name">res.partner.form.firstname</field>
22 <field name="model">res.partner</field>6 <field name="model">res.partner</field>
23 <field name="inherit_id" ref="base.view_partner_form"/>7 <field name="inherit_id" ref="base.view_partner_form"/>
24 <field name="arch" type="xml">8 <field name="arch" type="xml">
25 <field name="name" position="attributes">9 <field name="name" position="replace"/>
26 <attribute name="attrs">{'readonly': [('is_company', '=', False)], 'required': [('is_company', '=', True)]}</attribute>
27 </field>
28 <field name="category_id" position="before">10 <field name="category_id" position="before">
29 <group attrs="{'invisible': [('is_company', '=', True)]}">11 <group attrs="{'invisible': [('is_company', '=', True)]}">
30 <field name="lastname" attrs="{'required': [('is_company', '=', False)]}"/>12 <field name="firstname" attrs="{'required': [('is_company', '=', False)]}"/>
31 <field name="firstname"/>13 </group>
14 <group>
15 <field name="name" position="attributes">
16 <attribute name="attrs">{'readonly': [('is_company', '=', False)], 'required': [('is_company', '=', True)]}</attribute>
17 </field>
32 </group>18 </group>
33 </field>19 </field>
34 <!-- Add firstname and last name in inner contact form of child_ids -->20
35 <xpath expr="//form[@string='Contact']/sheet/div" position="after">21 <!-- Add first name and name in inner contact form of child_ids -->
36 <group attrs="{'invisible': [('is_company', '=', True)]}">22 <xpath expr="//form[@string='Contact']/sheet/div/h1/field[@name='name']" position="replace"/>
37 <field name="lastname" attrs="{'required': [('is_company', '=', False)]}"/>23 <xpath expr="//form[@string='Contact']/sheet/div/label" position="after">
24 <group>
38 <field name="firstname"/>25 <field name="firstname"/>
39 </group> 26 <field name="name"/>
40 </xpath>27 </group>
41 <xpath expr="//form[@string='Contact']/sheet/div/h1" position="after">28 </xpath>
42 <field name="is_company" on_change="onchange_type(is_company)" class="oe_inline"/>29
43 <label for="is_company" string="Is a Company?"/>)30 <label for="name" position="attributes">
44 </xpath>31 <attribute name="invisible">1</attribute>
4532 </label>
4633 <!-- Add first name and name in inner contact kanban view -->
34 <xpath expr="//t[@t-name='kanban-box']//div[@class='oe_module_desc']//field[@name='name']" position="replace">
35 <field name="firstname"/>
36 <field name="name"/>
37 </xpath>
47 </field>38 </field>
48 </record>39 </record>
40 <!-- Search view with full name-->
41 <record id="view_res_partner_filter_firstname" model="ir.ui.view">
42 <field name="name">res.partner.select</field>
43 <field name="model">res.partner</field>
44 <field name="inherit_id" ref="base.view_res_partner_filter"/>
45 <field name="arch" type="xml">
46 <field name="name" position="replace">
47 <field name="name"
48 filter_domain="['|','|',('full_name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"/>
49 </field>
50 </field>
51 </record>
4952
50 </data>53 </data>
51</openerp>54</openerp>
5255
=== modified file 'partner_firstname/res_user.py'
--- partner_firstname/res_user.py 2013-02-20 14:00:17 +0000
+++ partner_firstname/res_user.py 2014-01-22 23:37:10 +0000
@@ -17,10 +17,11 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#18#
19##############################################################################19##############################################################################
20from openerp.osv import orm20
2121from openerp.osv import orm, fields
2222
23class ResUsers(orm.Model):23
24class res_user(orm.Model):
24 """Allows user creation from user form as25 """Allows user creation from user form as
25 name is not in form"""26 name is not in form"""
2627
@@ -29,4 +30,4 @@
29 def create(self, cursor, uid, vals, context=None):30 def create(self, cursor, uid, vals, context=None):
30 if not vals.get('name'):31 if not vals.get('name'):
31 vals['name'] = vals['login']32 vals['name'] = vals['login']
32 return super(ResUsers, self).create(cursor, uid, vals, context=context)33 return super(res_user, self).create(cursor, uid, vals, context=context)

Subscribers

People subscribed via source and target branches

to all changes: