296
296
vals.update({'active': False})
297
297
current_contract = False
298
298
for contract in self.pool.get('hr.contract.msf').browse(cr, uid, contract_ids):
299
# Check current contract
299
300
if contract.current:
300
301
current_contract = True
301
302
if contract.date_end and contract.date_end < strftime('%Y-%m-%d'):
302
303
vals.update({'active': False})
306
vals.update({'job_id': contract.job_id.id})
303
307
# Desactivate employee if no current contract
304
308
if not current_contract:
305
309
vals.update({'active': False})
351
355
vals.update({field[1]: False})
353
357
vals.update({field[1]: line.get(field[0])})
358
# Update values for job
359
if line.get('fonction'):
360
job_ids = self.pool.get('hr.job').search(cr, uid, [('code', '=', line.get('fonction'))])
362
vals.update({'job_id': job_ids[0]})
354
363
# Add entry to database
355
364
new_line = self.pool.get('hr.contract.msf').create(cr, uid, vals)
357
366
res.append(new_line)
369
def update_job(self, cr, uid, ids, reader, context=None):
371
Read lines from reader and update database
377
# Check that no line with same code exist
378
if line.get('code', False):
379
search_ids = self.pool.get('hr.job').search(cr, uid, [('code', '=', line.get('code'))])
383
'homere_codeterrain': line.get('codeterrain') or False,
384
'homere_id_unique': line.get('id_unique') or False,
385
'code': line.get('code') or '',
386
'name': line.get('libelle') or '',
388
# Add entry to database
389
new_line = self.pool.get('hr.job').create(cr, uid, vals)
360
394
def button_validate(self, cr, uid, ids, context=None):
362
396
Open ZIP file and search staff.csv
387
422
filename = wiz.filename or ""
389
424
raise osv.except_osv(_('Error'), _('Given file is not a zip file!'))
425
# read the staff's job file
427
if zipobj.namelist() and job_file in zipobj.namelist():
428
job_reader = csv.DictReader(zipobj.open(job_file), quotechar='"', delimiter=',', doublequote=False, escapechar='\\')
429
job_ids = self.update_job(cr, uid, ids, job_reader, context=context)
430
# Do not raise error for job file because it's just a useful piece of data, but not more.
390
431
# read the contract file
391
432
contract_ids = False
392
433
if zipobj.namelist() and contract_file in zipobj.namelist():
394
435
contract_ids = self.update_contract(cr, uid, ids, contract_reader, context=context)
396
437
raise osv.except_osv(_('Error'), _('%s not found in given zip file!') % (contract_file,))
438
# read the staff file
397
439
if zipobj.namelist() and staff_file in zipobj.namelist():
398
440
# Doublequote and escapechar avoid some problems
399
441
reader = csv.reader(zipobj.open(staff_file), quotechar='"', delimiter=',', doublequote=False, escapechar='\\')