コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ

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

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

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

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
pythonattendance
1 返信
10383 ビュー
アバター
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
アバター
破棄
アバター
priyankahdp
著作者 最善の回答
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
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Acessing a columns field from in a method 解決済
python attendance
アバター
アバター
2
7月 16
7239
Auto logout not working properly for all employees in odoo18ce
attendance
アバター
アバター
アバター
2
10月 25
722
Sign in/sign out button not showing up for an employee
attendance
アバター
アバター
1
10月 25
6132
Biometric Attendence Machine
attendance
アバター
アバター
アバター
アバター
3
9月 25
2363
Help with ZK Biometric Time Integration (uFace 800) Across Multiple Branches
attendance
アバター
アバター
アバター
2
9月 25
3915
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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