Browse Source

[ADD] partner_firstname

pull/2/head
unknown 12 years ago
committed by Alexandre Fayolle
parent
commit
f81e47090f
  1. 21
      partner_firstname/__init__.py
  2. 37
      partner_firstname/__openerp__.py
  3. 31
      partner_firstname/i18n/de.po
  4. 32
      partner_firstname/i18n/en.po
  5. 31
      partner_firstname/i18n/fr.po
  6. 61
      partner_firstname/partner.py
  7. 37
      partner_firstname/partner_view.xml
  8. 31
      partner_firstname/res_user.py

21
partner_firstname/__init__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import partner
from . import res_user

37
partner_firstname/__openerp__.py

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name': 'Partner first name, last name',
'description': """Split first name and last name on res.partner.
The field 'name' becomes a stored function field concatenating lastname, firstname
""",
'version': '1.0',
'author': 'Camptocamp',
'category': 'MISC',
'website': 'http://www.camptocamp.com',
'depends': ['base'],
'data': ['partner_view.xml'],
'demo': [],
'test': [],
'auto_install': False,
'installable': True,
'images': []
}

31
partner_firstname/i18n/de.po

@ -0,0 +1,31 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * partner_firstname
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-02-04 10:36+0000\n"
"PO-Revision-Date: 2013-02-04 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
msgstr "Name"
#. module: partner_firstname
#: field:res.partner,firstname:0
msgid "Firstname"
msgstr "Vorname"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"
msgstr "Partner"

32
partner_firstname/i18n/en.po

@ -0,0 +1,32 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * partner_firstname
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-02-04 10:36+0000\n"
"PO-Revision-Date: 2013-02-04 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
msgstr "Lastname"
#. module: partner_firstname
#: field:res.partner,firstname:0
msgid "Firstname"
msgstr "Firstname"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"
msgstr "Partner"

31
partner_firstname/i18n/fr.po

@ -0,0 +1,31 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * partner_firstname
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-02-04 10:36+0000\n"
"PO-Revision-Date: 2013-02-04 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
msgstr "Nom"
#. module: partner_firstname
#: field:res.partner,firstname:0
msgid "Firstname"
msgstr "Prénom"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"
msgstr "Partenaire"

61
partner_firstname/partner.py

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import Model, fields
class ResPartner(Model):
"""Adds lastname and firstname, name become a stored function field"""
_inherit = 'res.partner'
def init(self, cursor):
cursor.execute('SELECT id FROM res_partner WHERE lastname IS NOT NULL Limit 1')
if not cursor.fetchone():
cursor.execute('UPDATE res_partner set lastname = name WHERE name IS NOT NULL')
def _compute_name_custom(self, cursor, uid, ids, fname, arg, context=None):
res = {}
for rec in self.read(cursor, uid, ids, ['firstname', 'lastname']):
name = rec['lastname'] + (u" " + rec['firstname'] if rec['firstname'] else u"")
res[rec['id']] = name
return res
def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):
return self.write(cursor, uid, partner_id, {'lastname': field_value})
def create(self, cursor, uid, vals, context=None):
"""To support data backward compatibility we have to keep this overwrite even if we
use fnct_inv: otherwise we can't create entry because lastname is mandatory and module
will not install if there is demo data"""
to_use = vals
if vals.get('name'):
corr_vals = vals.copy()
corr_vals['lastname'] = corr_vals['name']
del(corr_vals['name'])
to_use = corr_vals
return super(ResPartner, self).create(cursor, uid, to_use, context=context)
_columns = {'name': fields.function(_compute_name_custom, string="Name",
type="char", store=True,
select=True, readonly=True,
fnct_inv=_write_name),
'firstname': fields.char("Firstname"),
'lastname': fields.char("Lastname", required=True)}

37
partner_firstname/partner_view.xml

@ -0,0 +1,37 @@
<openerp>
<data>
<record id="view_partner_simple_form_firstname" model="ir.ui.view">
<field name="name">res.partner.simplified.form.firstname</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_simple_form"/>
<field name="arch" type="xml">
<field name="category_id" position="before">
<group>
<field name="lastname"/>
<field name="firstname"/>
</group>
</field>
</field>
</record>
<record id="view_partner_form_firstname" model="ir.ui.view">
<field name="name">res.partner.form.firstname</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="category_id" position="before">
<group>
<field name="lastname"/>
<field name="firstname"/>
</group>
</field>
<!-- Add firstname last name in contact for also -->
<xpath expr="//page[@string='Contacts']/field/form/div/group/field[@name='name']" position="after">
<field name="lastname"/>
<field name="firstname"/>
</xpath>
</field>
</record>
</data>
</openerp>

31
partner_firstname/res_user.py

@ -0,0 +1,31 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class ResUsers(orm.Model):
"""Allows user creation from user form as
name is not in form"""
_inherit = 'res.users'
def create(self, cursor, uid, vals, context=None):
vals['name'] = vals['login']
return super(ResUsers, self).create(cursor, uid, vals, context=context)
Loading…
Cancel
Save