Files
daily_odoo_timesheet/README.md
sas.fajri c9bf004a4f Initial commit: Odoo timesheet automation scripts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 10:18:08 +07:00

237 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Odoo Timesheet Automation
Script untuk otomatisasi input timesheet Odoo berdasarkan commit Git harian.
---
## Alur Harian
```
Commit dengan format "TASKCODE - deskripsi"
16:55 — cron otomatis baca commit hari ini dari semua repo
Cari task_id di Odoo berdasarkan kode task
Hitung jam pro-rata (total = 8 jam/hari)
Simpan ke pending_YYYY-MM-DD.json + kirim notifikasi macOS
Kamu jalankan upload_pending.py --session-id XXX
Preview → konfirmasi y/N → upload ke Odoo
```
---
## Format Commit
Setiap commit **wajib** menggunakan format:
```
TASKCODE - deskripsi singkat
```
Contoh:
```
6D9QD6 - buat api endpoint baru
FHM28 - fix bug validasi form
```
Kode task akan dipakai untuk mencari task di Odoo secara otomatis.
---
## Repo yang Dipantau
| Repo | Project Odoo |
|------|-------------|
| `REPO_CPONE/BE_CPONE` | CPONE |
| `REPO_CPONE/FE_CPONE` | CPONE |
| `REPO_CPONE_DASHBOARD` | CPONE |
| `REPO_GITEA_IBL` | IBL |
| `REPO_GITEA_KD` | Support Kedungdoro |
| `REPO_GITLAB_PRAMITA/bisone` | Support Pramita |
## Project ID
| Nama | ID |
|------|----|
| CPONE | 123 |
| IBL | 186 |
| Support Pramita | 70 |
| SAS | 92 |
| Support Kedungdoro | 77 |
---
## Scripts
### `daily_timesheet.py`
Ambil commit hari ini dari semua repo, cari task di Odoo, hitung pro-rata, simpan pending.
```bash
# Dry run — preview tanpa simpan
python3 daily_timesheet.py \
--session-id <session_id> \
--author fajri \
--user-id 41 --employee-id 37 \
--dry-run
# Simpan pending.json + kirim notifikasi macOS
python3 daily_timesheet.py \
--session-id <session_id> \
--author fajri \
--user-id 41 --employee-id 37 \
--save-pending
# Tanggal custom
python3 daily_timesheet.py ... --date 2026-05-27
```
| Parameter | Keterangan |
|-----------|-----------|
| `--session-id` | Cookie session Odoo |
| `--author` | Filter git author |
| `--user-id` | ID user Odoo |
| `--employee-id` | ID employee Odoo |
| `--date` | Tanggal (default: hari ini) |
| `--dry-run` | Preview saja, tidak upload |
| `--save-pending` | Simpan ke file + notifikasi |
---
### `upload_pending.py`
Upload timesheet dari file pending hasil `daily_timesheet.py`. Jalankan setelah menerima notifikasi macOS.
```bash
python3 upload_pending.py --session-id <session_id>
# Tanggal tertentu
python3 upload_pending.py --session-id <session_id> --date 2026-05-27
```
Setelah upload sukses, file `pending_YYYY-MM-DD.json` otomatis diganti nama jadi `done_YYYY-MM-DD.json`.
---
### `search_task.py`
Cari task di Odoo berdasarkan kode dan project.
```bash
python3 search_task.py \
--session-id <session_id> \
--name "[6D9QD6]" \
--project-id CPONE
```
| Parameter | Keterangan |
|-----------|-----------|
| `--name` | Kata kunci pencarian |
| `--project-id` | Nama project atau ID angka |
| `--limit` | Maks hasil (default: 8) |
---
### `upload_timesheet.py`
Upload satu atau banyak timesheet entry secara manual.
```bash
# Satu entry
python3 upload_timesheet.py \
--session-id <session_id> \
--name "review API" \
--task-id 51352 \
--unit-amount 2.0 \
--user-id 41 --employee-id 37 \
--project-id CPONE
# Banyak entry sekaligus
python3 upload_timesheet.py \
--session-id <session_id> \
--name "review API" "fix bug" \
--task-id 51352 51353 \
--unit-amount 2.0 1.5 \
--user-id 41 41 \
--employee-id 37 37 \
--project-id CPONE SAS
```
---
### `git_commits.py`
Lihat commit dari semua repo per project tanpa upload ke Odoo.
```bash
python3 git_commits.py --author fajri --since 2026-05-01 --until 2026-05-28
```
---
### `sync_timesheet.py`
Upload timesheet langsung dari commit (tanpa pending flow). Cocok untuk upload manual hari-hari sebelumnya.
```bash
# Dry run
python3 sync_timesheet.py \
--session-id <session_id> \
--author fajri \
--user-id 41 --employee-id 37 \
--since 2026-05-27 --until 2026-05-27 \
--dry-run
# Upload
python3 sync_timesheet.py \
--session-id <session_id> \
--author fajri \
--user-id 41 --employee-id 37 \
--since 2026-05-27
```
---
## Cron Otomatis
Cron berjalan setiap SeninJumat jam **16:55**:
```
55 16 * * 1-5 run_daily.sh
```
Edit `run_daily.sh` untuk mengubah `SESSION_ID` jika expired:
```bash
# run_daily.sh
SESSION_ID="session_id_baru_disini"
```
Log tersimpan di `logs/daily_YYYY-MM-DD.log`.
---
## Session ID Expired
Kalau session expired, notifikasi macOS akan muncul:
```
⚠️ Timesheet Gagal
Session Odoo expired. Buka run_daily.sh dan ganti SESSION_ID.
```
**Cara ambil session_id baru:**
1. Buka Odoo di browser → login
2. Tekan `F12` → tab **Application** (Chrome) / **Storage** (Firefox)
3. Pilih **Cookies** → cari `session_id`
4. Copy nilainya → paste ke `SESSION_ID` di `run_daily.sh`
---
## Konfigurasi Default
| Parameter | Nilai |
|-----------|-------|
| User ID | 41 |
| Employee ID | 37 |
| Total jam/hari | 8 |
| Odoo URL | `https://odoo.minipc.sismedika.biz.id` |