Browse Source

[FIX] Create Sql constraint anyway

[CHG] Improve the _write_name method
* trying to coerce to the correct lastname if the firstname is untouched
* resetting the firstname if contact is a company
[FIX] Avoid to replicate the firstname into the name when duplicating a partner
[FIX] Avoid to replicate the firstname into the name when duplicating a user
[CHG] Restore the required attribute of the field name in user form
[CHG] Beautify the inner form for children contacts (placing fields as in the main form)
[FIX] Allow edition of the field name in the inner form if child is a company
pull/2/head
Jonathan Nemry 11 years ago
parent
commit
3bbde88780
  1. 17
      partner_firstname/i18n/de.po
  2. 24
      partner_firstname/i18n/en.po
  3. 17
      partner_firstname/i18n/fr.po
  4. 17
      partner_firstname/i18n/nl.po
  5. 21
      partner_firstname/i18n/partner_firstname.pot
  6. 41
      partner_firstname/partner.py
  7. 19
      partner_firstname/partner_view.xml
  8. 18
      partner_firstname/res_user.py
  9. 1
      partner_firstname/res_user_view.xml

17
partner_firstname/i18n/de.po

@ -15,6 +15,18 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: code:addons/partner_firstname/partner.py:76
#: code:addons/partner_firstname/res_user.py:35
#, python-format
msgid "%s (copy)"
msgstr "%s (kopie)"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users
msgid "Users"
msgstr "Benutzer"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
@ -25,6 +37,11 @@ msgstr "Name"
msgid "Firstname"
msgstr "Vorname"
#. module: partner_firstname
#: view:res.partner:0
msgid "Is a Company?"
msgstr "Ist ein Unternehmen?"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"

24
partner_firstname/i18n/en.po

@ -16,17 +16,33 @@ msgstr ""
"Plural-Forms: \n"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
msgstr "Lastname"
#: code:addons/partner_firstname/partner.py:76
#: code:addons/partner_firstname/res_user.py:35
#, python-format
msgid "%s (copy)"
msgstr "%s (copy)"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users
msgid "Users"
msgstr "Users"
#. module: partner_firstname
#: field:res.partner,firstname:0
msgid "Firstname"
msgstr "Firstname"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
msgstr "Lastname"
#. module: partner_firstname
#: view:res.partner:0
msgid "Is a Company?"
msgstr "Is a Company?"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"
msgstr "Partner"

17
partner_firstname/i18n/fr.po

@ -15,6 +15,18 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: code:addons/partner_firstname/partner.py:76
#: code:addons/partner_firstname/res_user.py:35
#, python-format
msgid "%s (copy)"
msgstr "%s (copie)"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users
msgid "Users"
msgstr "Utilisateur"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
@ -25,6 +37,11 @@ msgstr "Nom"
msgid "Firstname"
msgstr "Prénom"
#. module: partner_firstname
#: view:res.partner:0
msgid "Is a Company?"
msgstr "Est une société?"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"

17
partner_firstname/i18n/nl.po

@ -15,6 +15,18 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: code:addons/partner_firstname/partner.py:76
#: code:addons/partner_firstname/res_user.py:35
#, python-format
msgid "%s (copy)"
msgstr "%s (kopie)"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users
msgid "Users"
msgstr "Gebruikers"
#. module: partner_firstname
#: field:res.partner,lastname:0
msgid "Lastname"
@ -25,6 +37,11 @@ msgstr "Achternaam"
msgid "Firstname"
msgstr "Voornaam"
#. module: partner_firstname
#: view:res.partner:0
msgid "Is a Company?"
msgstr "Is een bedrijf?"
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"

21
partner_firstname/i18n/partner_firstname.pot

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-10-03 16:09+0000\n"
"PO-Revision-Date: 2013-10-03 16:09+0000\n"
"POT-Creation-Date: 2014-01-22 14:09+0000\n"
"PO-Revision-Date: 2014-01-22 14:09+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@ -15,6 +15,18 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_firstname
#: code:addons/partner_firstname/partner.py:76
#: code:addons/partner_firstname/res_user.py:35
#, python-format
msgid "%s (copy)"
msgstr ""
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users
msgid "Users"
msgstr ""
#. module: partner_firstname
#: field:res.partner,firstname:0
msgid "Firstname"
@ -25,6 +37,11 @@ msgstr ""
msgid "Lastname"
msgstr ""
#. module: partner_firstname
#: view:res.partner:0
msgid "Is a Company?"
msgstr ""
#. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_partner
msgid "Partner"

41
partner_firstname/partner.py

@ -18,6 +18,7 @@
#
##############################################################################
from openerp.osv.orm import Model, fields
from openerp.tools.translate import _
class ResPartner(Model):
@ -29,6 +30,10 @@ class ResPartner(Model):
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')
# Create Sql constraint if table is not empty
cursor.execute('SELECT id FROM res_partner Limit 1')
if cursor.fetchone():
cursor.execute('ALTER TABLE res_partner ALTER COLUMN lastname SET NOT NULL')
def _compute_name_custom(self, cursor, uid, ids, fname, arg, context=None):
res = {}
@ -41,13 +46,39 @@ class ResPartner(Model):
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}, context=context)
"""
# Try to reverse the effect of _compute_name_custom:
# * if is_company is True then lastname = name and firstname False
# * if firstname change in the new name: lastname is set to new name, firstname is reset
# * if only lastname change in the new name: lastname is updated accordingly, firstname remains untouched
"""
vals = {'lastname': field_value, 'firstname': False}
dict = self.read(cursor, uid, [partner_id], ['firstname', 'is_company'], context=context)[0]
if not dict['is_company']:
to_check = ' %s' % dict['firstname']
if field_value.endswith(to_check):
vals['lastname'] = field_value[:-len(to_check)]
del(vals['firstname'])
return self.write(cursor, uid, partner_id, vals, context=context)
def copy_data(self, cr, uid, id, default=None, context=None):
"""
# Avoid to replicate the firstname into the name when duplicating a partner
"""
default = default or {}
if not default.get('lastname'):
default = default.copy()
default['lastname'] = _('%s (copy)') % self.read(cr, uid, [id], ['lastname'], context=context)[0]['lastname']
if default.get('name'):
del(default['name'])
return super(ResPartner, self).copy_data(cr, uid, id, default, context=context)
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 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()

19
partner_firstname/partner_view.xml

@ -32,15 +32,26 @@
</group>
</field>
<!-- Add firstname and last name in inner contact form of child_ids -->
<xpath expr="//form[@string='Contact']/sheet/div" position="after">
<xpath expr="//form[@string='Contact']/sheet//field[@name='category_id']" position="before">
<group attrs="{'invisible': [('is_company', '=', True)]}">
<field name="lastname" attrs="{'required': [('is_company', '=', False)]}"/>
<field name="firstname"/>
</group>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/div/h1" position="after">
<field name="is_company" on_change="onchange_type(is_company)" class="oe_inline"/>
<label for="is_company" string="Is a Company?"/>)
<xpath expr="//form[@string='Contact']/sheet//field[@name='category_id']" position="attributes">
<attribute name="style"/>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/div/label" position="replace">
<div class="oe_edit_only">
<label for="name"/> (
<field name="is_company" on_change="onchange_type(is_company)" class="oe_inline"/>
<label for="is_company" string="Is a Company?"/>)
</div>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/div/h1/field[@name='name']" position="attributes">
<div class="oe_edit_only">
<attribute name="attrs">{'readonly': [('is_company', '=', False)], 'required': [('is_company', '=', True)]}</attribute>
</div>
</xpath>

18
partner_firstname/res_user.py

@ -18,15 +18,21 @@
#
##############################################################################
from openerp.osv import orm
from openerp.tools.translate import _
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):
if not vals.get('name'):
vals['name'] = vals['login']
return super(ResUsers, self).create(cursor, uid, vals, context=context)
def copy_data(self, cr, uid, id, default=None, context=None):
"""
# Avoid to replicate the firstname into the name when duplicating a user
"""
default = default or {}
if not default.get('lastname'):
default = default.copy()
default['lastname'] = _('%s (copy)') % self.read(cr, uid, [id], ['lastname'], context=context)[0]['lastname']
if default.get('name'):
del(default['name'])
return super(ResUsers, self).copy_data(cr, uid, id, default, context=context)

1
partner_firstname/res_user_view.xml

@ -8,6 +8,7 @@
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="readonly">False</attribute>
<attribute name="required">True</attribute>
</field>
</field>
</record>

Loading…
Cancel
Save