From 3bbde88780c2ae1f7d79a02179ab200dde3f64ce Mon Sep 17 00:00:00 2001 From: Jonathan Nemry Date: Wed, 22 Jan 2014 16:46:07 +0100 Subject: [PATCH 1/6] [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 --- partner_firstname/i18n/de.po | 17 ++++++++ partner_firstname/i18n/en.po | 24 ++++++++++-- partner_firstname/i18n/fr.po | 17 ++++++++ partner_firstname/i18n/nl.po | 17 ++++++++ partner_firstname/i18n/partner_firstname.pot | 21 +++++++++- partner_firstname/partner.py | 41 +++++++++++++++++--- partner_firstname/partner_view.xml | 19 +++++++-- partner_firstname/res_user.py | 18 ++++++--- partner_firstname/res_user_view.xml | 1 + 9 files changed, 154 insertions(+), 21 deletions(-) diff --git a/partner_firstname/i18n/de.po b/partner_firstname/i18n/de.po index 5565405d5..65fdef123 100644 --- a/partner_firstname/i18n/de.po +++ b/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" diff --git a/partner_firstname/i18n/en.po b/partner_firstname/i18n/en.po index 26e710fec..53f3034f8 100644 --- a/partner_firstname/i18n/en.po +++ b/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" - diff --git a/partner_firstname/i18n/fr.po b/partner_firstname/i18n/fr.po index 5155afb0c..682b35041 100644 --- a/partner_firstname/i18n/fr.po +++ b/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" diff --git a/partner_firstname/i18n/nl.po b/partner_firstname/i18n/nl.po index 898d22c22..a8eb29ef4 100644 --- a/partner_firstname/i18n/nl.po +++ b/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" diff --git a/partner_firstname/i18n/partner_firstname.pot b/partner_firstname/i18n/partner_firstname.pot index 96518f758..52c9ec190 100644 --- a/partner_firstname/i18n/partner_firstname.pot +++ b/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" diff --git a/partner_firstname/partner.py b/partner_firstname/partner.py index 42fed16eb..5e95c4c95 100644 --- a/partner_firstname/partner.py +++ b/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() diff --git a/partner_firstname/partner_view.xml b/partner_firstname/partner_view.xml index 8f0368373..9a88c6e80 100644 --- a/partner_firstname/partner_view.xml +++ b/partner_firstname/partner_view.xml @@ -32,15 +32,26 @@ - + - - -