Doc_chelvyn/Mito/Sfa/Integrasi/SFA — Reward Claim ke Odoo ...

368 lines
24 KiB
Markdown
Raw Permalink Normal View History

---
judul: SFA — Reward Claim ke Odoo (Draft Vendor Bill)
proyek: SFA CMS · mito_odoo
terkait: Mito · Odoo 18 · SFA Mobile
stack: Odoo 18 (mito_base REST API) · Laravel 11 · Filament 3 · MySQL · PostgreSQL
kategori: Integrasi
status: CMS di-push ke develop (46fc3c7) · Odoo di-commit lokal cj/api (a5cc341e), belum di-push · teruji di lokal 14-10-2026
tipe: dokumen-internal
tags:
- sfa
- reward
- odoo
- vendor-bill
- integrasi
diperbarui: 2026-10-15
---
> Index: [[SFA — Index]] · Kategori: **Integrasi** · FDD: [[SFA–CMS Reward Claim Integration to Odoo 18]] (v0.4) ·
> Fitur induk: [[SFA — Reward]]
>
> Setiap claim reward yang sudah memotong saldo di CMS dikirim ke Odoo dan dibuatkan **Draft Vendor Bill**:
> **vendor sesuai user**, **product sesuai parameter**, **amount sesuai claim**. Integrasi satu arah (CMS → Odoo),
> aman di-retry karena idempotent per Claim ID. Posting & pembayaran tetap oleh Finance di Odoo.
>
> Diagram untuk meeting: [[SFA — Reward Claim ke Odoo (diagram).excalidraw]] — buka di excalidraw.com lewat menu *Open*.
# SFA — Reward Claim ke Odoo (Draft Vendor Bill)
## Alur Claim → Draft Vendor Bill
Kode status dan error di bawah sama persis dengan kode (`integration_status` / `status` di tabel `reward_claim`,
`error.code` dari API Odoo).
```mermaid
flowchart TD
A["SFA Mobile / Admin CMS:<br/>Claim full balance"] --> B["CMS: reward_claim dibuat + saldo dipotong<br/>status PROCESSING · integration QUEUED"]
B --> C["Worker odoo:push-reward-claims (tiap menit)<br/>ambil QUEUED · RETRY jatuh tempo · SENDING macet > 10 mnt"]
C --> D["Kunci claim → SENDING<br/>POST /api/v1/reward-bills"]
D --> E{"Odoo: Claim ID sudah<br/>punya bill?"}
E -- "ya" --> E1["200 · created=false<br/>bill lama dikembalikan"]
E -- "tidak" --> F{"nominal > 0?"}
F -- "tidak" --> F1["422 validation_error"]
F -- "ya" --> G{"Vendor dengan CMS User ID<br/>(company cocok)?"}
G -- "tidak ada" --> G1["422 vendor_not_found"]
G -- "lebih dari 1" --> G2["422 vendor_duplicate"]
G -- "diarsipkan" --> G3["422 vendor_inactive"]
G -- "tepat 1, aktif" --> H{"Default Reward Product<br/>valid?"}
H -- "kosong" --> H1["422 reward_product_not_set"]
H -- "tidak aktif / bukan Purchase /<br/>company lain" --> H2["422 reward_product_invalid"]
H -- "ya" --> I["Create Draft Vendor Bill<br/>201 · created=true"]
I -. "request paralel, Claim ID sama" .-> I1["409 claim_in_progress"]
E1 --> S["CMS: SUCCESS · DRAFT_CREATED<br/>simpan odoo_bill_id + odoo_bill_ref"]
I --> S
F1 & G1 & G2 & G3 & H1 & H2 --> P["CMS: PERMANENT_ERROR · NEEDS_RECONCILIATION<br/>tidak di-retry otomatis"]
P --> Q["Admin perbaiki data di Odoo<br/>→ tombol Kirim Ulang ke Odoo"]
Q --> D
D -- "timeout · koneksi · 5xx · 401 · 404" --> R["CMS: RETRY · PENDING_RETRY<br/>jeda 1 · 5 · 15 · 30 · 60 mnt"]
I1 --> R
R -- "next_retry_at lewat" --> C
R -- "gagal ke-10" --> P
S -.-> T["Finance: review → Post → Bayar di Odoo<br/>(di luar integrasi)"]
classDef ok fill:#d1fae5,stroke:#059669,color:#064e3b
classDef err fill:#fee2e2,stroke:#dc2626,color:#7f1d1d
classDef warn fill:#fef3c7,stroke:#d97706,color:#78350f
classDef todo fill:#f3f4f6,stroke:#9ca3af,color:#374151,stroke-dasharray:4 3
class E1,I,S ok
class F1,G1,G2,G3,H1,H2,P err
class R,Q,I1 warn
class T todo
```
Hijau = sukses, merah = ditolak (tidak di-retry otomatis), kuning = retry / butuh tindakan admin, abu-abu putus-putus =
di luar integrasi. **Saldo user tidak pernah dikembalikan otomatis** di cabang mana pun (FDD §7).
## Alur Status Integrasi
```mermaid
stateDiagram-v2
[*] --> QUEUED : claim dibuat (Node API / CMS)
QUEUED --> SENDING : worker mengunci claim
SENDING --> SUCCESS : 200 / 201
SENDING --> PERMANENT_ERROR : 422 (mapping / konfigurasi)
SENDING --> RETRY : timeout, koneksi, 5xx, 409, 401, 404
SENDING --> SENDING : macet lebih dari 10 menit, diambil ulang
RETRY --> SENDING : next_retry_at lewat, atau tombol Kirim Ulang
RETRY --> PERMANENT_ERROR : gagal ke-10
PERMANENT_ERROR --> SENDING : tombol Kirim Ulang ke Odoo
SUCCESS --> [*]
```
| `integration_status` | `status` claim | Arti | Tombol **Kirim Ulang ke Odoo** |
|---|---|---|---|
| `QUEUED` | `PROCESSING` | Baru, menunggu worker | Tidak (otomatis) |
| `SENDING` | `PROCESSING` | Sedang dikirim | Tidak |
| `SUCCESS` | `DRAFT_CREATED` | Draft bill ada di Odoo (**bukan** sudah posted/dibayar) | Tidak |
| `RETRY` | `PENDING_RETRY` | Gagal sementara, dicoba lagi otomatis | Ya (kirim sekarang) |
| `PERMANENT_ERROR` | `NEEDS_RECONCILIATION` | Data Odoo belum benar, atau gagal 10x | Ya (setelah data diperbaiki) |
## Retry Setelah Timeout — Kenapa Tidak Dobel
```mermaid
sequenceDiagram
participant W as Worker CMS
participant O as Odoo /api/v1/reward-bills
participant DB as PostgreSQL Odoo
W->>O: POST claim_id=RCL261014000001
O->>DB: INSERT account_move (snk_reward_claim_ref = RCL…001)
Note over W,O: Respons hilang (timeout) — bill sebenarnya sudah dibuat
W->>W: RETRY · next_retry_at = +1 menit
W->>O: POST claim_id=RCL261014000001 (sama)
O->>DB: cari snk_reward_claim_ref = RCL…001
DB-->>O: bill #28148 sudah ada
O-->>W: 200 · created=false · id 28148
W->>W: SUCCESS · DRAFT_CREATED
Note over O,DB: Dua request bersamaan: INSERT kedua ditolak unique constraint<br/>→ 409 claim_in_progress → CMS retry → dapat bill yang sama
```
---
## 1. Keputusan Teknis
| # | Hal | Keputusan | Alasan |
|---|---|---|---|
| 1 | Metode integrasi (FDD §10 #1) | **Custom REST API di `mito_base`** (`POST /api/v1/reward-bills`), bukan External API XML-RPC | Field vendor & setting product wajib ditambah lewat module juga; idempotensi + validasi jadi **satu transaksi** di Odoo (External API = 3–4 call terpisah, rawan dobel); API key cuma bisa satu aksi ini (External API butuh user Accounting/Settings); error code jelas untuk CMS; polanya sama dengan endpoint IMEI/customer/product yang sudah dipakai `OdooClient` |
| 2 | Nama field CMS User ID (FDD §10 #2) | `snk_cms_user_id` (Char), bukan `x_cms_user_id` | Prefix `x_` untuk field Studio/manual; module ini konsisten pakai `snk_`. Char sesuai rekomendasi FDD §3.1 |
| 3 | Isi CMS User ID | **`users.id` CMS** (akun login yang claim), bukan `empl_code` employee | Claim tercatat per `users.id`. Tidak semua pengklaim punya employee (konsumen hasil registrasi); di data lokal user Rahmat (`57`) dan employee Rahmat (`20250404`) bahkan tidak terhubung. Kolom **CMS User ID** dimunculkan di CMS supaya admin bisa menyalinnya |
| 4 | Keunikan (FDD §10 #3) | `UNIQUE(snk_cms_user_id)` global & `UNIQUE(snk_reward_claim_ref)` lewat `_sql_constraints` | Tahan request paralel (cek Python bisa lolos dua-duanya), sekaligus jadi index. NULL tidak bentrok. Kalau nanti unik per company → `unique(snk_cms_user_id, company_id)` |
| 5 | Idempotensi | Claim ID (`claim_code` CMS) disimpan di field khusus `account.move.snk_reward_claim_ref`, bukan hanya di `ref` | `ref` (Bill Reference) bisa diedit Finance dan tidak bisa diberi unique. Field khusus `readonly`, `copy=False` |
| 6 | Company (FDD §10 #4) | Company default user API (`env.company`) | Satu company saat ini. Product setting disimpan per company (`res.company`), siap multi-company |
| 7 | Jurnal, akun, pajak (FDD §10 #6) | **Default Odoo**: jurnal purchase default, akun expense dari product/kategori, pajak dari Vendor Taxes product | Menunggu keputusan Finance — lihat §8 |
| 8 | Klasifikasi gagal | `422` = permanen (data/konfigurasi salah, tidak di-retry); lainnya = sementara (retry bertahap) | Mengulang request yang mapping-nya salah tidak akan pernah berhasil; timeout/Odoo mati bisa pulih sendiri |
| 9 | Referensi bill balik ke CMS | Disimpan dari **respons create saja** (`odoo_bill_id`, `odoo_bill_ref`), tidak ada sinkronisasi status setelahnya | FDD §8 (one-way) vs Acceptance Criteria #7 (referensi tersimpan) saling bertentangan → diambil jalan tengah. Perlu dikonfirmasi |
## 2. Setup Sebelum Dipakai
**Odoo** (sekali per database):
1. Buat product, misalnya **Reward SFA**: tipe *Service*, centang **Purchase** (= `purchase_ok`), *Vendor Taxes*
kosong, isi **Expense Account** di tab Accounting sesuai keputusan Finance.
2. **Accounting → Configuration → Settings → Vendor Bills → Default Reward Product** → pilih product tadi → **Save**.
3. Tiap vendor penerima reward: **Contact → tab Sales & Purchase → CMS User ID** = `users.id` CMS. Field hanya
tampil untuk grup *Accounting Administrator*. Contact wajib punya Account Receivable/Payable (lihat §9 temuan #1).
4. **Settings → Technical → System Parameters**: `mito_base.api_key` (string acak ≥32 karakter,
`openssl rand -hex 32`) dan `mito_base.api_user_id` (user yang boleh membuat Vendor Bill).
**CMS** (`.env`): `ODOO_URL`, `ODOO_DB`, `MITO_API_KEY` (= `mito_base.api_key`). Cron `php artisan schedule:run`
tiap menit harus aktif (sama dengan sync IMEI).
---
## 3. Penjelasan Kode — Odoo (`mito_odoo/mito/mito_base`)
Commit `a5cc341e` `[ADD][MITO] REST API Draft Vendor Bill dari Claim Reward SFA` (branch `cj/api`). Versi module
`18.0.1.0.1` → **`18.0.1.0.2`**. Tanpa migration script: hanya menambah kolom + constraint, tidak ada perubahan destruktif.
### 3.1 `models/account/snk_reward_claim_bill.py` (baru) — logika utama
Semua aturan bisnis ada di sini, bukan di controller, supaya bisa di-test dengan `TransactionCase` dan bisa dipanggil
dari jalur lain (misalnya server action) tanpa HTTP.
| Bagian | Isi |
|---|---|
| `RewardClaimBillError(UserError)` | Exception dengan atribut `code` (`vendor_not_found`, dst.). Controller mengubahnya jadi HTTP `422` + `error.code` |
| Field `snk_reward_claim_ref` | Char, `copy=False`, `readonly=True`. Duplikat bill (menu *Duplicate*) tidak membawa Claim ID |
| `_sql_constraints` `snk_reward_claim_ref_uniq` | `unique(snk_reward_claim_ref)` — jaminan satu Claim ID = satu bill di level database |
| `_snk_find_reward_claim_bill()` | Cari bill berdasarkan Claim ID dengan **`sudo()`**: cek duplikat harus melihat semua bill, termasuk yang tersembunyi ir.rule Operating Unit user API. `sudo()` hanya untuk satu search ini |
| `_snk_get_reward_vendor()` | Cari `res.partner` dengan `snk_cms_user_id` sama persis dan `company_id` kosong / sama. `active_test=False` supaya vendor arsip terdeteksi sebagai `vendor_inactive`, bukan `vendor_not_found`. `limit=2` cukup untuk mendeteksi duplikat |
| `_snk_get_reward_product()` | Baca `env.company.snk_reward_claim_product_id`; tolak kalau kosong, tidak aktif, bukan *Purchase*, atau milik company lain |
| `snk_create_reward_claim_bill()` | Urutan: validasi wajib isi → **cek bill lama dulu** (return `(bill, False)`) → nominal > 0 → vendor → product → `create()` `in_invoice` dengan 1 line (qty 1, `price_unit` = amount, label `Reward Claim <Claim ID>`), `ref` + `snk_reward_claim_ref` = Claim ID, `invoice_date` = tanggal claim bila dikirim |
| `savepoint()` + `UniqueViolation` | Kalau dua request paralel lolos cek "bill lama", INSERT kedua ditolak constraint → savepoint di-rollback → `claim_in_progress` (409). Cursor tetap sehat |
Cek bill lama dilakukan **sebelum** validasi lain dengan sengaja: retry claim yang sudah punya bill harus selalu sukses,
walaupun setelah itu vendor diarsipkan atau setting product diubah.
### 3.2 `controllers/api/reward_bills.py` (baru) — endpoint REST
- `@api_route('/reward-bills', methods=['POST'], tags=['Reward'], body=..., response=...)`: otomatis terdaftar di
Swagger `/api/v1/docs` (lewat `API_REGISTRY` di `core.py`) dan mewarisi auth Bearer, format JSON, serta rollback saat error.
- Parsing `amount`: helper `get_float` di `core.py` menganggap `0` sama dengan "kosong" (`0 in (None, '', False)` di
Python bernilai `True`). Angka dari JSON diterima langsung supaya `amount: 0` ditolak dengan pesan yang benar
("Nominal claim harus lebih dari 0"), bukan "amount is required". `core.py` sengaja tidak diubah karena dipakai endpoint lain.
- `claim_date` divalidasi format `YYYY-MM-DD` (`fields.Date.to_date`).
- `RewardClaimBillError` → `ApiError(message, 422 | 409, code)`. `_ERROR_STATUS` memetakan `claim_in_progress` ke 409.
- `serialize_bill()`: `name` dikirim `null` selama draft belum bernomor (Odoo 18 mengisi `False`/`/`), `created`
membedakan 201 dan 200.
### 3.3 `models/base/res_partner.py` — field CMS User ID
`snk_cms_user_id = fields.Char(copy=False, tracking=True)` + `unique(snk_cms_user_id)`. `tracking=True` mencatat setiap
perubahan mapping di chatter contact (audit FDD §3.3). `copy=False` supaya duplikat contact tidak langsung bentrok constraint.
### 3.4 `models/base/snk_res_company.py` + `snk_res_config_settings.py` — Default Reward Product
- `res.company.snk_reward_claim_product_id`: Many2one `product.product` (varian, bisa langsung dipakai di invoice
line — FDD §3.2), domain `purchase_ok = True`, `check_company=True`.
- `res.config.settings.snk_reward_claim_product_id`: `related='company_id.…'`, `readonly=False` → disimpan otomatis
oleh `set_values()` bawaan saat tombol **Save** di Settings ditekan. Disimpan per company, bukan di
`ir.config_parameter`, supaya siap multi-company dan tidak butuh hak *Settings* untuk membacanya.
### 3.5 View
| File | Perubahan |
|---|---|
| `views/base/res_partner.xml` | View baru `view_partner_property_form_snk_cms_user` inherit `account.view_partner_property_form`: field CMS User ID tepat setelah *Payment Terms* (tab Sales & Purchase → Purchase), `groups="account.group_account_manager"` |
| `views/account/snk_account_setting_view.xml` | Setting **Default Reward Product** di block `account_vendor_bills` (record yang sama dengan *Print Out Parameter*), `company_dependent="1"`, `no_create` |
### 3.6 `tests/test_reward_claim_bill.py` (baru) — 11 test
`TransactionCase`, tag `post_install -at_install`. Mencakup: bill draft terbentuk benar, retry Claim ID sama →
bill sama (count 1), `claim_date` → Bill Date, CMS User ID di-trim, `vendor_not_found`, `vendor_inactive`,
`reward_product_not_set`, `reward_product_invalid`, nominal 0/negatif, Claim ID kosong, unique CMS User ID
(`IntegrityError` di dalam savepoint).
---
## 4. Penjelasan Kode — CMS (`snk_sfa-cms`)
Commit `46fc3c7` `add : kirim claim reward ke Odoo sebagai Draft Vendor Bill (outbox tiap menit)` — di-push ke `develop`.
Tidak ada migration: semua kolom (`integration_status`, `retry_count`, `next_retry_at`, `odoo_bill_id`, …) sudah dibuat
di migration reward `2026_10_13_000003`.
### 4.1 `app/Services/OdooClient.php` — tambah `post()`
- `get()` dan `post()` sekarang memakai satu `parse()`: sukses → `['data', 'meta', 'status']`; gagal →
**`OdooApiException`** (turunan `RuntimeException`, jadi pemanggil lama yang menangkap `RuntimeException`/`Throwable`
tetap jalan).
- Retry koneksi bawaan (`retry(3, 2000)` untuk `ConnectionException`) tetap berlaku juga untuk POST. Aman karena endpoint
idempotent.
### 4.2 `app/Services/OdooApiException.php` (baru)
Membawa `status` (HTTP), `errorCode` (`error.code` Odoo, mis. `vendor_not_found`) dan `errorMessage` (pesan asli Odoo
untuk ditampilkan ke admin).
### 4.3 `app/Services/RewardClaimOdooService.php` (baru) — inti pengiriman
| Method | Isi |
|---|---|
| `dueQuery()` | Claim yang siap dikirim: `QUEUED`, `RETRY` dengan `next_retry_at` sudah lewat (atau null), dan `SENDING` yang macet > `STALE_SENDING_MINUTES` (10) — misalnya proses PHP mati di tengah request |
| `send($claim, $force)` | `acquire()` → `post('reward-bills', {claim_id: claim_code, cms_user_id: (string) user_id, amount, claim_date: requested_at WIB})` → tandai hasil. Return `false` kalau claim sedang dipegang proses lain |
| `acquire()` | **Update bersyarat** (`UPDATE … SET integration_status='SENDING' WHERE id=? AND <masih due>`), dicek jumlah baris yang berubah. Dua worker atau worker + klik admin tidak bisa memegang claim yang sama. `$force` (tombol / `--claim`) melewati syarat jatuh tempo tapi tetap menolak `SUCCESS` dan `SENDING` yang masih segar |
| `markSuccess()` | `SUCCESS` / `DRAFT_CREATED`, simpan `odoo_bill_id`, `odoo_bill_ref` = nomor bill, atau Bill Reference (= Claim ID) kalau draft belum bernomor; error dibersihkan |
| `markPermanent()` | `PERMANENT_ERROR` / `NEEDS_RECONCILIATION`, simpan `error_code` + `error_message`, `next_retry_at` null |
| `markRetry()` | `RETRY` / `PENDING_RETRY`, `retry_count + 1`, `next_retry_at` = sekarang + `RETRY_DELAYS` (1, 5, 15, 30, 60 menit; selebihnya 60). Gagal ke-`MAX_RETRY` (10) → `markPermanent()` |
Pemetaan error: `OdooApiException` 422 → permanen; `OdooApiException` lain (401, 404, 409, 5xx) dan
`ConnectionException` (timeout) → retry; `Throwable` lain → retry + `Log::error`.
### 4.4 `app/Console/Commands/PushRewardClaimsToOdoo.php` (baru) — worker
- `php artisan odoo:push-reward-claims` — ambil `dueQuery()` urut `id` (claim lama duluan), `--limit=50` per jalan,
dilindungi `Cache::lock` (600 detik) supaya tidak ada dua worker paralel.
- `--claim=RCL…` — kirim satu claim tertentu dengan `force` (termasuk `PERMANENT_ERROR`). Berguna untuk debug di server.
- Output per claim: `RCL… → STATUS (bill #id) [error_code] pesan`.
### 4.5 `routes/console.php` — jadwal
`Schedule::command('odoo:push-reward-claims')->everyMinute()->withoutOverlapping(10)`, log ke
`storage/logs/odoo-push-reward-claims.log`. Jadi claim masuk Odoo **paling lambat ±1 menit** setelah user klik Claim.
### 4.6 Filament
| File | Perubahan |
|---|---|
| `RewardClaimResource.php` | Action `sendToOdooAction()` **Kirim Ulang ke Odoo**: hanya tampil untuk `PERMANENT_ERROR` & `RETRY`; dialog konfirmasi menampilkan error terakhir; hasil → notifikasi hijau (Bill #id) atau merah persistent ([error_code] pesan). Kolom + entry **CMS User ID** (`user_id`, copyable) |
| `RewardClaimResource/Pages/ViewRewardClaim.php` | Action yang sama di header halaman detail |
| `RewardBalanceResource.php` | Kolom + entry **CMS User ID** dengan petunjuk "Isi di Odoo: Vendor → Sales & Purchase → CMS User ID" |
| `UserResource.php` | Kolom `id` diberi label **CMS User ID**, tampil default (sebelumnya tersembunyi), copyable & searchable |
---
## 5. Kontrak API
`POST /api/v1/reward-bills` · Header `Authorization: Bearer <mito_base.api_key>` · Swagger: `/api/v1/docs` tag **Reward**
```json
{ "claim_id": "RCL261014000001", "cms_user_id": "57", "amount": 250000, "claim_date": "2026-10-14" }
```
| Field | Wajib | Keterangan |
|---|---|---|
| `claim_id` | ✅ | `reward_claim.claim_code`, idempotency key |
| `cms_user_id` | ✅ | `reward_claim.user_id` (= `users.id`), dicocokkan ke `res.partner.snk_cms_user_id` |
| `amount` | ✅ | > 0, IDR |
| `claim_date` | – | `YYYY-MM-DD` → Bill Date. Kosong = diisi Finance / saat posting |
| `description` | – | Ditambahkan ke label line setelah Claim ID |
Respons sukses (`201` baru, `200` sudah ada):
```json
{ "success": true, "data": { "id": 28148, "name": null, "state": "draft", "claim_id": "RCL261014000001",
"ref": "RCL261014000001", "partner": {"id": 11081, "name": "Administrator test"},
"product": {"id": 67653, "name": "Reward SFA"}, "invoice_date": "2026-10-14", "currency": "IDR",
"amount_untaxed": 250000.0, "amount_tax": 0.0, "amount_total": 250000.0, "created": true } }
```
| HTTP | `error.code` | Arti | Perlakuan CMS |
|---|---|---|---|
| 422 | `vendor_not_found` | Tidak ada vendor dengan CMS User ID ini | Permanen |
| 422 | `vendor_duplicate` | CMS User ID di >1 vendor (secara teori dicegah constraint) | Permanen |
| 422 | `vendor_inactive` | Vendor diarsipkan | Permanen |
| 422 | `reward_product_not_set` | Default Reward Product kosong | Permanen |
| 422 | `reward_product_invalid` | Product tidak aktif / bukan Purchase / company lain | Permanen |
| 422 | `validation_error` | Field wajib kosong, nominal ≤ 0, format tanggal salah | Permanen |
| 409 | `claim_in_progress` | Request paralel Claim ID sama | Retry |
| 401 | `unauthorized` | API key salah / tidak ada | Retry |
| 404 | – | Endpoint belum di-deploy di server Odoo tujuan | Retry |
---
## 6. Pengujian (lokal, 14-10-2026)
**Unit test Odoo** di `MITO_DEV`: `--test-tags /mito_base:TestRewardClaimBill` → **11 test, 0 gagal** (1,29 detik). Saat
menjalankan test, server web lokal sedang memakai 8069, jadi perlu `--http-port=8099 --gevent-port=8098`.
**Manual via API** (curl ke `localhost:8070`):
| # | Skenario | Hasil |
|---|---|---|
| 1 | Claim baru, Rp 250.000 | ✅ `201`, bill **#28148** Draft, vendor + product + amount benar, pajak 0 |
| 2 | Kirim ulang Claim ID sama | ✅ `200`, `created:false`, id sama — 1 bill di DB |
| 3 | `cms_user_id` tidak dikenal | ✅ `422 vendor_not_found` |
| 4 | `amount` 0 / negatif / tidak dikirim | ✅ `422` pesan sesuai |
| 5 | Tanpa Authorization | ✅ `401 unauthorized` |
| 6 | `claim_date` format salah | ✅ `422 validation_error` |
**Dari CMS** (`odoo:push-reward-claims --claim=` dan tombol): claim `RCL261013000001` → `PERMANENT_ERROR
[vendor_not_found]` (CMS User ID `57` belum dipasang di Odoo — perilaku benar). Klik tombol saat `.env` masih mengarah ke
mitodev → `RETRY [http_404]` karena endpoint belum di-deploy di mitodev — juga perilaku benar.
## 7. Deploy
| Repo | Commit | Status |
|---|---|---|
| `mito_odoo` | `a5cc341e` di `cj/api` | ⚠️ **Belum di-push.** `cj/api` lokal bercabang dari `origin/cj/api` (commit IMEI lama ter-rebase ulang). Rencana: rebase commit reward ke atas `origin/develop`, `-u mito_base` + test ulang di lokal, lalu push (fast-forward) dan PR ke `develop` |
| `snk_sfa-cms` | `46fc3c7` di `develop` | ✅ Di-push 14-10-2026, belum di-deploy |
Urutan wajib: **Odoo dulu** (`-u mito_base --stop-after-init`, setup §2), **baru CMS**. Kalau CMS naik duluan, claim
akan `RETRY [http_404]` sampai Odoo siap (tidak rusak, hanya tertunda; setelah 10x jadi `PERMANENT_ERROR` dan perlu
diklik Kirim Ulang).
## 8. Keputusan Terbuka (bahan meeting)
| # | Hal | Kondisi sekarang | Perlu keputusan |
|---|---|---|---|
| 1 | **Expense account** | Ikut kategori product *All* → `510.1000.00 Harga Pokok Penjualan` | Akun beban reward/promosi yang benar → isi di product Reward SFA (tanpa ubah kode) |
| 2 | **Journal** | Default purchase journal → `ADV Advance Purchase` | Jurnal mana? Kalau perlu tetap, tambah setting **Default Reward Journal** (kecil, di samping Default Reward Product) |
| 3 | **Pajak** | Ikut Vendor Taxes product (sekarang kosong) | Termasuk / di luar pajak? PPh atas reward? |
| 4 | **Operating Unit / analytic** | Kosong di bill | Perlu? Kalau ya, ambil dari mana (OU vendor?) |
| 5 | **Pemilik mapping** | Admin Accounting mengisi CMS User ID manual per vendor | Siapa yang bertanggung jawab, kapan diisi (sebelum user boleh claim?) |
| 6 | **Vendor = siapa** | Contact Odoo apa pun yang diberi CMS User ID | Konsumen individu, dealer, atau per program? Perlu master vendor baru per user? |
| 7 | **Referensi bill di CMS** | Disimpan dari respons create (FDD §8 vs AC #7 bertentangan) | Konfirmasi ke tim FDD |
| 8 | **Keunikan lintas company** | Global | Cukup global, atau per company? |
## 9. Temuan Selama Pengujian
1. **`MITO_DEV`: 407 dari 677 contact aktif tidak punya Account Receivable/Payable** (tidak ada `ir.default` untuk
`property_account_receivable_id`/`payable_id`), sehingga form contact menolak disimpan. Tidak terkait fitur ini; untuk
testing diisi manual `115.1010.00 Piutang Usaha` / `211.1010.00 Hutang Usaha`. Cek apakah production sama.
2. **CMS User ID ≠ Employee Code.** Admin sempat mengisi `20250404` (kode employee Rahmat), padahal claim milik
`users.id` `57`. Solusinya kolom CMS User ID ditampilkan di Users, Reward Balance, dan Claim History.
3. `get_float` di `controllers/api/core.py` menganggap `0` = kosong (`0 == False`). Diakali di endpoint reward; endpoint
lain (`qty`, `price_unit` di sale order) punya perilaku yang sama — kandidat perbaikan terpisah.
4. `mito_base.api_key` di `MITO_DEV` hanya 12 karakter — server lain wajib ≥32 karakter.
5. Untuk test lokal, `.env` CMS diarahkan ke `http://localhost:8070` / `MITO_DEV` (nilai mitodev dikomentari di atasnya).
**Kembalikan sebelum kerja lain** yang butuh sync dari mitodev.