콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
9482 화면

Please help me to sort out this issue.My code is like below.i'm going to read savefile.txt and write it in another text backup file['attendance.csv'] here read and write parts works perfectly but in delete function its gives below mentioned error thanks

def text_files_upload(self, cr, uid, ids, context=None):
    attendance_v={}
    attendanceList=[]
    attendance_obj = self.pool.get('text.based.attendance')
    id=0
    f = open("/home/priyan/Desktop/Store/HR_Module/attendance/savefile.txt",'rU')
    c = csv.reader(f, delimiter=':', skipinitialspace=True)
    for line in c:
        if line:
            unique_record_value=line[0][0:18]
            name=line[0]    
            machine_code=line[0]
            location_code=line[0]
            in_out='sign_in'
            #check whether records exists here
            search_condition = [('unique_record', '=', unique_record_value)]
            attendance_ids = attendance_obj.search(cr, uid, search_condition, context=context)
            attendance_similar_objs = self.browse(cr, uid, attendance_ids, context=context)

            #attendance_obj.unlink(cr, uid, [attendance_similar_objs.id], context=context)

            if not attendance_similar_objs:
                unique_record_value=line[0][0:18]
                name=line[0]    
                machine_code=line[0]
                location_code=line[0]
                in_out='sign_in'
                if line[0][17]==1:
                    in_out='sign_in'
                else:
                    in_out='sign_out'
                sign_date=line[0]
                sign_time=line[1]
                name=name[3:9]
                machine_code=machine_code[0:3]
                location_code=location_code[9:11]
                sign_date=sign_date[11:17]
                sign_time=sign_time[0:4]
                fulldate=sign_date+':'+sign_time
                fulldate=datetime.strptime(fulldate, '%y%m%d:%H%M')
                id=id+1
                attendance_v = {'dup_id': id,'status': 0,'name': name, 'machine_code': machine_code, 'location_code': location_code, 'in_out': in_out,'date': fulldate,'unique_record':unique_record_value}
                attendance_obj.create(cr, uid, attendance_v, context=context)
            attendanceList.append(attendance_v.items())
            with open("attendance.csv", "w") as f:
                writer = csv.writer(f)
                writer.writerows(attendanceList)
    f.close()
    os.remove(f)
    return False

here is my error

2013-10-29 09:13:36,708 10046 ERROR 201310281610 openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 275, in text_files_upload
    os.remove(f)
TypeError: coercing to Unicode: need string or buffer, file found
2013-10-29 09:13:36,709 10046 ERROR 201310281610 openerp.netsvc: coercing to Unicode: need string or buffer, file found
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 275, in text_files_upload
    os.remove(f)
TypeError: coercing to Unicode: need string or buffer, file found
2013-10-29 09:13:36,714 10046 INFO 201310281610 werkzeug: 127.0.0.1 - - [29/Oct/2013 09:13:36] "POST /web/dataset/call_button HTTP/1.1" 200 -
2013-10-29 09:13:36,708 10046 ERROR 201310281610 openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 275, in text_files_upload
    os.remove(f)
TypeError: coercing to Unicode: need string or buffer, file found
2013-10-29 09:13:36,709 10046 ERROR 201310281610 openerp.netsvc: coercing to Unicode: need string or buffer, file found
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 275, in text_files_upload
    os.remove(f)
TypeError: coercing to Unicode: need string or buffer, file found

and also here mention my savefile.txt [its generated from fingerprint machine]

09D043770021301312:1007*0084*02538G

09D022195021301312:0918*0083*:3:5:G

09D021891011301312:0906*0082*:3:5:G
아바타
취소
작성자 베스트 답변
filename="/home/priyan/Desktop/Store/HR_Module/attendance/savefile.txt"

# snip

f = open(filename,'rU')

# snip

f.close()
os.remove(filename)
return False

now its sorted :-)

아바타
취소
관련 게시물 답글 화면 활동
2
7월 16
6354
1
4월 25
723
0
3월 25
800
0
3월 25
735
0
1월 25
684