From c7da365ff90b6f448919acfb997924f60d85bd04 Mon Sep 17 00:00:00 2001 From: Serpent Consulting Services Date: Wed, 5 Sep 2012 01:57:27 +0530 Subject: [PATCH] [FIX] base_partner_surname : bugfix and code optimization (../addons/extra-trunk rev 5791) --- base_partner_surname/__init__.py | 2 +- base_partner_surname/__openerp__.py | 9 +++-- base_partner_surname/partner.py | 47 ++++++++++++++-------- base_partner_surname/partner_view.xml | 56 +++++++++++++-------------- 4 files changed, 64 insertions(+), 50 deletions(-) diff --git a/base_partner_surname/__init__.py b/base_partner_surname/__init__.py index b98977515..f863de6d8 100644 --- a/base_partner_surname/__init__.py +++ b/base_partner_surname/__init__.py @@ -19,5 +19,5 @@ # ############################################################################## import partner -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/base_partner_surname/__openerp__.py b/base_partner_surname/__openerp__.py index cd4878a34..f4ede8364 100755 --- a/base_partner_surname/__openerp__.py +++ b/base_partner_surname/__openerp__.py @@ -21,19 +21,20 @@ { "name" : "Base Partner Surname", "version" : "1.0", - "author" : "Tiny", + "author" : "Tiny, Serpent Consulting Services", "website" : "http://www.openerp.com", "category" : "Generic Modules/Base", "description": """ -This module use for seperate surname from contact name of partner. Now You can give first name & last name on contact Name. -This module is deprecated, it is higly recommended to use base_contact instead. +This module is used for separate surname from contact name of partner. Now You can give first name & last name on contact Name. +This module is deprecated, it is highly recommended to use base_contact instead. """, "depends" : ["base"], "init_xml" : [ ], "demo_xml" : [ ], "update_xml" : [ "partner_view.xml" ], - "installable": True + "installable": True, + "auto_install": False } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_partner_surname/partner.py b/base_partner_surname/partner.py index 80f0ed086..13932c6d1 100644 --- a/base_partner_surname/partner.py +++ b/base_partner_surname/partner.py @@ -30,34 +30,47 @@ class res_partner_address(osv.osv): 'name' : fields.char('Name', size=128, readonly=True), } - def write(self, cr, uid, ids, vals, context={}): - first_name = '' - last_name = '' - if 'first_name' in vals and vals['first_name']: - first_name = vals['first_name'] - if 'last_name' in vals and vals['last_name']: - last_name = vals['last_name'] + def write(self, cr, uid, ids, vals, context=None): + if context is None: + context = {} + if isinstance(ids,list): + ids = ids[0] + data = self.read(cr, uid, ids, ['first_name','last_name'], context=context) + first_name = data['first_name'] or '' + if 'first_name' in vals: + first_name = vals['first_name'] or '' + + last_name = data['last_name'] or '' + if 'last_name' in vals: + last_name = vals['last_name'] or '' - vals['name'] = first_name + ' ' + last_name + if first_name or last_name: + vals['name'] = first_name + ' ' + last_name return super(res_partner_address, self).write(cr, uid, ids, vals, context) - def create(self, cr, uid, vals, context={}): + def create(self, cr, uid, vals, context=None): + if context is None: + context = {} first_name = '' last_name = '' - if 'first_name' in vals and vals['first_name']: - first_name = vals['first_name'] - if 'last_name' in vals and vals['last_name']: - last_name = vals['last_name'] - - vals['name'] = first_name + ' ' + last_name + if 'first_name' in vals: + first_name = vals['first_name'] or '' + if 'last_name' in vals: + last_name = vals['last_name'] or '' + + if first_name or last_name: + vals['name'] = first_name + ' ' + last_name return super(res_partner_address, self).create(cr, uid, vals, context) - def onchange_name(self, cr, uid, id, first_name, last_name, context={}): + def onchange_name(self, cr, uid, id, first_name, last_name): + res = {} if not first_name: first_name = '' if not last_name: last_name = '' - return {'value': {'name': first_name + ' ' + last_name}} + if first_name or last_name: + res = {'name': first_name + ' ' + last_name} + return {'value': res} res_partner_address() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_partner_surname/partner_view.xml b/base_partner_surname/partner_view.xml index b078d29a0..205242e68 100644 --- a/base_partner_surname/partner_view.xml +++ b/base_partner_surname/partner_view.xml @@ -1,7 +1,7 @@ - + res.partner.address.form1.inherit res.partner.address form @@ -21,35 +21,35 @@ form - -
- - - - - - - - - - - - - - - - - - - - - - - - - + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+