237 lines
9.0 KiB
Markdown
237 lines
9.0 KiB
Markdown
---
|
||
proyek: Mito
|
||
modul: mito_base · snk_jobsheet_operation
|
||
odoo: "18.0"
|
||
kategori: Plan & Tracking
|
||
periode: 2026-06-24 → 2026-06-25
|
||
status: 2 selesai · 2 pending
|
||
sumber: snk_mito/config/plan.md
|
||
tags:
|
||
- mito
|
||
- plan
|
||
- tracking
|
||
- financial-report
|
||
- discount
|
||
---
|
||
|
||
> Index: [[Mito — Index]] · Kategori: **Plan & Tracking**
|
||
>
|
||
> Tiga perubahan logika berdampak luas beserta keputusan bisnis & konsekuensinya:
|
||
> bypass global discount (boleh numpuk tanpa batas), fix HPP `snk_cogs` yang selalu 0,
|
||
> dan isu negative stock yang membuat sebagian COGS tetap 0.
|
||
|
||
# Plan & Tracking — Perubahan Logika Bisnis (MITO)
|
||
|
||
Dokumen ringkas untuk melacak perubahan logika yang dampaknya luas, beserta
|
||
keputusan bisnis & konsekuensi yang sudah disepakati.
|
||
|
||
---
|
||
|
||
## [2026-06-24] Bypass Global Discount — Boleh Numpuk Tanpa Batas
|
||
|
||
**Status:** ✅ Done
|
||
**Tag commit:** `[DEV][MITO]`
|
||
**File terkait:**
|
||
- `mito/snk_jobsheet_operation/models/sale_order.py` → method `_apply_program_reward`
|
||
|
||
---
|
||
|
||
### Konteks / Trigger
|
||
|
||
User mendapat error saat apply reward global discount manual lewat wizard:
|
||
|
||
```
|
||
Validation Error
|
||
Sebagian reward gagal diterapkan:
|
||
test cj global discount 2 – 20% on your order: A better global discount is already applied.
|
||
```
|
||
|
||
### Root Cause
|
||
|
||
Error berasal dari **core Odoo** (`sale_loyalty._apply_program_reward`), bukan code custom.
|
||
Core Odoo menjamin **1 SO = maksimal 1 global discount**: kalau sudah ada global
|
||
discount, yang baru hanya akan *replace* kalau lebih besar, atau *ditolak* kalau
|
||
yang lama sudah ≥.
|
||
|
||
Override custom sebelumnya hanya mem-bypass cek itu **kalau reward terlink ke AP Form**
|
||
(`reward.program_id.snk_jobsheet_id` terisi). Reward "test cj global discount 2"
|
||
tidak punya `snk_jobsheet_id`, jadi jatuh ke `super()` → kena aturan core → ditolak.
|
||
|
||
### Keputusan Bisnis (Blueprint Company)
|
||
|
||
> Semua global discount **boleh menumpuk (stack), tanpa batas** — bukan hanya yang
|
||
> terlink AP Form.
|
||
|
||
Scope: **global**, berlaku untuk semua jalur (manual wizard + auto-apply promo).
|
||
|
||
### Perubahan
|
||
|
||
Gerbang `snk_jobsheet_id` dilepas. Kondisi bypass dari:
|
||
|
||
```python
|
||
if reward.is_global_discount and reward.program_id.snk_jobsheet_id:
|
||
```
|
||
|
||
menjadi:
|
||
|
||
```python
|
||
if reward.is_global_discount:
|
||
```
|
||
|
||
Body method tidak berubah: pengecekan poin & coupon `future` tetap jalan; yang
|
||
di-skip hanya cek "better global discount" + `_reset_loyalty` (agar diskon tiered
|
||
tidak terhapus).
|
||
|
||
### Konsekuensi (Disepakati, Tanpa Guard)
|
||
|
||
- ⚠️ **Tidak ada batas.** Beberapa global discount bisa numpuk → total order
|
||
berpotensi minus / margin bocor kalau program auto-apply tidak diatur hati-hati.
|
||
- ⚠️ Berlaku juga untuk promo **otomatis**, bukan cuma pilihan manual user.
|
||
- ✅ Dari sisi performa **lebih ringan**, karena skip `_reset_loyalty`.
|
||
|
||
### Catatan Teknis
|
||
|
||
- **Tidak perlu migration / version bump** — murni perubahan logika Python, tidak
|
||
menyentuh struktur DB.
|
||
|
||
### Follow-up (jika nanti dibutuhkan)
|
||
|
||
- [ ] Tambahkan guard `amount_total < 0` → raise ValidationError, kalau ada keluhan
|
||
total order minus.
|
||
- [ ] Audit program global discount yang `applies_on='current'` (auto-apply) agar
|
||
tidak numpuk tanpa sengaja.
|
||
|
||
---
|
||
|
||
## [2026-06-24] Fix HPP (snk_cogs) Selalu 0 di Financial Report
|
||
|
||
**Status:** ✅ Fix utama done & verified — fix duplikasi multi-baris pending
|
||
**Tag commit:** `[FIX][MITO]`
|
||
**File terkait:**
|
||
- `mito/mito_base/wizards/account/snk_financial_invoice_report_wizard.py` → `_build_main_query` (LATERAL cogs)
|
||
|
||
---
|
||
|
||
### Konteks / Trigger
|
||
|
||
Diskusi dari chat tim (Krisna): flow HPP seharusnya "lookup ke category ambil
|
||
field expense account, lalu ambil account move line invoice yang accountnya
|
||
dari field expense itu" — beda dari cara yang sudah ada di kode (filter
|
||
`display_type='cogs'` doang).
|
||
|
||
### Root Cause (Dikonfirmasi via Query Langsung ke DB `MITO_DEV_JUN`)
|
||
|
||
Setiap baris COGS di Odoo (Anglo-Saxon costing) dibuat **berpasangan** double-entry,
|
||
keduanya ditandai `display_type='cogs'`:
|
||
|
||
| account_id | Nama | account_type | Sisi |
|
||
|---|---|---|---|
|
||
| 1723 | Harga Pokok Penjualan | `expense_direct_cost` | Debit (+) |
|
||
| 1677 | Barang Dalam Transit | `asset_current` | Kredit (-) |
|
||
|
||
Query lama:
|
||
```sql
|
||
WHERE c.display_type = 'cogs' -- nangkap KEDUA kaki
|
||
SUM(c.balance) -- +12000 + (-12000) = 0
|
||
```
|
||
|
||
**Akibat: `snk_cogs` SELALU 0 untuk SEMUA invoice** — bukan edge case. Verifikasi
|
||
di tabel `snk_financial_report` sebelum fix: 18/18 baris (100%) `snk_cogs = 0`.
|
||
GPM & Ratio GPM ikut salah karena formulanya `snk_sub_total - snk_cogs`.
|
||
|
||
### Kenapa Flow Krisna "Benar Arahnya" (Tapi Tidak Dipakai Langsung)
|
||
|
||
Filter Krisna (account = category expense account) cuma menangkap kaki **debit**
|
||
saja — itu yang bikin nilainya tidak 0. Tapi tidak dipakai langsung karena:
|
||
- `product_category.property_account_expense_categ_id` disimpan sebagai **jsonb
|
||
company-dependent property field** di Odoo 18 — perlu resolve per company_id,
|
||
nambah kompleksitas join.
|
||
- Rapuh kalau ada override expense account di level **produk** (bukan category) —
|
||
filter ke category bisa miss baris yang sebenarnya valid.
|
||
|
||
### Fix yang Dipakai
|
||
|
||
Filter pakai `account_account.account_type = 'expense_direct_cost'` — tipe akun
|
||
standar Odoo untuk COGS, otomatis isolasi kaki debit/HPP saja, robust terhadap
|
||
override account apapun di produk/category:
|
||
|
||
```sql
|
||
LEFT JOIN LATERAL (
|
||
SELECT SUM(c.balance) AS amount
|
||
FROM account_move_line c
|
||
JOIN account_account a ON a.id = c.account_id
|
||
WHERE c.display_type = 'cogs'
|
||
AND a.account_type = 'expense_direct_cost'
|
||
AND c.move_id = fl.move_id
|
||
AND c.product_id = fl.product_id
|
||
) cogs ON true
|
||
```
|
||
|
||
Sign untuk credit note (`out_refund`) sudah konsisten dengan `fl.sign` yang
|
||
sudah ada di kode (dicek manual, tidak perlu ubah logic sign).
|
||
|
||
### Verifikasi
|
||
|
||
- Manual psql: move 427, product 35258 → cogs 0 → **12000** (sesuai DPP 120000,
|
||
margin 90%).
|
||
- Generate ulang via `odoo shell` (`action_generate`): 2366 baris, hanya 54 baris
|
||
(~2%) masih 0 (kemungkinan produk tanpa entry valuation — wajar, bukan bug).
|
||
- Spot check row: `snk_sub_total_amount=120000, snk_cogs=12000, snk_gpm=108000,
|
||
snk_ratio_gpm=90` — konsisten.
|
||
|
||
### Konsekuensi
|
||
|
||
- ⚠️ **Semua laporan HPP/GPM historis yang sudah di-generate user salah (selalu
|
||
HPP=0, GPM=Subtotal, Ratio GPM=100%)**. Perlu re-generate ulang semua data
|
||
existing di `snk_financial_report` untuk semua user, bukan cuma yang baru.
|
||
- Tidak ada migration/version bump — perubahan SQL di wizard, bukan struktur DB.
|
||
|
||
### Follow-up — Masih Pending
|
||
|
||
- [ ] **Bug duplikasi multi-baris produk dalam 1 invoice**: ditemukan invoice
|
||
dengan 799 baris produk sama (kemungkinan dari IMEI tracking, tiap serial
|
||
= 1 baris). LATERAL cogs match by `move_id+product_id` saja → nilai cogs
|
||
yang sama ke-duplikasi ke SETIAP baris produk itu saat di-SUM di level
|
||
invoice/report. Perlu alokasi proporsional per qty (mirip pola ongkir di
|
||
baris 211-213 file yang sama). **Belum di-fix, prioritas selanjutnya.**
|
||
- [ ] Re-generate `snk_financial_report` untuk semua user (data lama HPP=0 semua).
|
||
- [ ] Investigasi 54 baris yang masih HPP=0 setelah fix — pastikan wajar (produk
|
||
non-valuation) bukan bug lain.
|
||
|
||
|
||
|
||
# Plan / Backlog — mito_odoo
|
||
|
||
## [PENDING] Negative Stock → HPP hilang (COGS = 0) di sebagian invoice
|
||
|
||
**Status:** Belum dikerjakan. Ditunda — pakai solusi simpel COGS dulu (report sudah benar menampilkan apa adanya).
|
||
|
||
**Tanggal temuan:** 2026-06-25
|
||
**DB:** MITO_DEV_JUN
|
||
|
||
### Gejala
|
||
Di financial invoice report, sebagian baris produk **HPP (snk_cogs) = 0** padahal produk storable + valuation `real_time`.
|
||
Contoh: **SI/2026/06/00005** produk **MX-003** → HPP 0, padahal `standard_price` = 297.619.
|
||
|
||
### Akar masalah (BUKAN bug report)
|
||
Report jujur menampilkan data akuntansi. Penyebab di **level inventory**:
|
||
- Delivery **WH/OUT/00314** (untuk SI/2026/06/00005) punya valuation layer **value = 0, unit_cost = 0**.
|
||
- Artinya saat barang keluar, **tidak ada stok bernilai** untuk dikonsumsi → gejala **negative stock**.
|
||
- Anglo-Saxon Odoo: `price_unit = 0` → `amount_currency = qty × 0 = 0` →
|
||
`stock_account/models/account_move.py` (~L134) `if is_zero(amount_currency): continue`
|
||
→ **baris `display_type='cogs'` TIDAK dibuat** → di report HPP = 0.
|
||
|
||
Bandingan: layer normal MX-003 (WH/OUT/00238) value = −580.000. Yang bermasalah (WH/OUT/00314) = 0.
|
||
|
||
### Terkait
|
||
- PR `da1e478 [FIX] Fix Negative Stock` (sudah merge ke main). Perlu dicek apakah sudah meng-cover re-valuasi kasus ini.
|
||
|
||
### Rencana penyelesaian (nanti)
|
||
1. **Ukur skala:** hitung berapa banyak `stock_valuation_layer` outgoing dengan `value = 0 / unit_cost = 0` di MITO_DEV_JUN (dan prod).
|
||
2. **Cek mekanisme re-valuasi** negative stock yang ada di `da1e478` — apakah otomatis mengoreksi layer 0 setelah stok masuk.
|
||
3. Kalau belum: siapkan **re-valuation** layer outgoing yang ber-value 0 (isi unit_cost benar) + regenerate cogs / koreksi akuntansi.
|
||
4. **Preventif (proses bisnis):** pastikan stok tidak minus sebelum delivery di-validasi.
|
||
|
||
### Catatan
|
||
- Fix report COGS sendiri (filter akun HPP `expense_direct_cost` + ambil `amount_currency`) **sudah benar** dan tidak perlu menunggu isu ini.
|