Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to using Python, read Text file & if not exists then write to another file and delete?

Odoberať

Get notified when there's activity on this post

This question has been flagged
pythonattendance
1 Odpoveď
10382 Zobrazenia
Avatar
priyankahdp

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
0
Avatar
Zrušiť
Avatar
priyankahdp
Autor Best Answer
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 :-)

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Acessing a columns field from in a method Solved
python attendance
Avatar
Avatar
2
júl 16
7239
Auto logout not working properly for all employees in odoo18ce
attendance
Avatar
Avatar
Avatar
2
okt 25
722
Sign in/sign out button not showing up for an employee
attendance
Avatar
Avatar
1
okt 25
6132
Biometric Attendence Machine
attendance
Avatar
Avatar
Avatar
Avatar
3
sep 25
2363
Help with ZK Biometric Time Integration (uFace 800) Across Multiple Branches
attendance
Avatar
Avatar
Avatar
2
sep 25
3915
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now