# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
#    (<http://www.savoirfairelinux.com>).
#
#    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, fields


class hr_employee(orm.Model):
    _inherit = 'hr.employee'

    def init(self, cursor):
        cursor.execute('''\
SELECT id
FROM hr_employee
WHERE lastname IS NOT NULL
LIMIT 1''')
        if not cursor.fetchone():
            cursor.execute('''\
UPDATE hr_employee
SET lastname = name_related
WHERE name_related IS NOT NULL''')

    def create(self, cursor, uid, vals, context=None):
        names = (vals['firstname'], vals['lastname'])
        vals['name'] = " ".join(s for s in names if s)
        return super(hr_employee, self).create(
            cursor, uid, vals, context=context)

    _columns = {
        'firstname': fields.char("Firstname"),
        'lastname': fields.char("Lastname", required=True)
    }

@@ -1455,22 +1455,29 @@
     
+first
 name
-s
  = 
-(
 vals
-%5B
+.get(
 'fir
@@ -1487,16 +1487,38 @@
 ame'
-%5D, vals%5B
+)%0A        lastname = vals.get(
 'las
@@ -1523,17 +1523,16 @@
 astname'
-%5D
 )%0A      
@@ -1537,54 +1537,192 @@
     
-vals%5B'name'%5D = %22 %22.join(s for s in names if s)
+if firstname or lastname:%0A            names = (firstname, lastname)%0A            vals%5B'name'%5D = %22 %22.join(s for s in names if s)%0A        else:%0A            vals%5B'lastname'%5D = vals%5B'name'%5D
 %0A   

Fix issue when no lastname is supplied