213 lines
7.9 KiB
Markdown
213 lines
7.9 KiB
Markdown
---
|
|
proyek: Mito
|
|
modul: mito_base
|
|
odoo: "18.0"
|
|
kategori: Discount & Loyalty
|
|
status: Tracking — root cause teridentifikasi (data pajak produk ongkir)
|
|
sumber: snk_mito/config/TRACKING_DISCOUNT_ONGKIR.md
|
|
tags:
|
|
- mito
|
|
- discount
|
|
- ongkir
|
|
- tracking
|
|
---
|
|
|
|
> Index: [[Mito — Index]] · Kategori: **Discount & Loyalty**
|
|
>
|
|
> Baris discount jadi dobel saat SO punya baris ongkir: wizard group per kombinasi pajak,
|
|
> barang ber-VAT dan ongkir tanpa pajak jatuh ke group berbeda. Berisi query cek DB + pola log.
|
|
> Konteks wizard-nya: [[Mito — Diskon Bertingkat & Loyalty Reward]]
|
|
|
|
# Tracking: Discount Spesial "Kebagi Dua" saat Ada Ongkir
|
|
|
|
> **Gejala:** Saat apply Discount Spesial / Diskon Bertingkat di SO yang punya baris
|
|
> ongkir (Delivery Cost), baris discount yang dibuat jadi **dobel** — satu untuk
|
|
> barang (ber-VAT) dan satu lagi untuk ongkir (tanpa VAT).
|
|
>
|
|
> **Contoh nyata (SO S00313, dev):** discount `-44.943,81` (VAT) + `-112,37` (no-tax).
|
|
|
|
---
|
|
|
|
## 1. Akar Masalah (Ringkas)
|
|
|
|
Bukan bug acak. Wizard discount meng-**group order line berdasarkan kombinasi pajak**:
|
|
|
|
```python
|
|
# mito/mito_base/wizards/sale/sale_order_discount.py
|
|
taxes = line.tax_id.flatten_taxes_hierarchy()
|
|
fixed_taxes = taxes.filtered(lambda t: t.amount_type == 'fixed')
|
|
taxes -= fixed_taxes
|
|
total_price_per_tax_groups[taxes] += line_amount # <-- group per tax
|
|
```
|
|
|
|
- Barang punya **VAT** → masuk group A
|
|
- Ongkir **tanpa pajak** → masuk group B (terpisah)
|
|
- Untuk **tiap tier**, dibuat **1 baris discount per group** → kalau ada 2 group, jadi dobel.
|
|
|
|
**Kenapa lokal "bisa", dev "belum":**
|
|
Perbedaannya **DATA pajak di produk ongkir**, bukan kode.
|
|
- Di lokal: produk ongkir kemungkinan **punya VAT** (atau baris ongkir tidak ada saat tes) → semua 1 group → 1 baris discount per tier. ✅
|
|
- Di dev: produk ongkir **tanpa pajak** → 2 group → discount kebagi dua. ❌
|
|
|
|
---
|
|
|
|
## 2. Cek di DB DEV (PostgreSQL)
|
|
|
|
> Jalankan di **DB lokal** DAN **DB dev**, lalu **bandingkan** hasilnya.
|
|
> Port dev (dari docker-compose): host `localhost`, port `47833`.
|
|
|
|
```bash
|
|
# Masuk ke psql dev (sesuaikan nama db & user)
|
|
psql -h localhost -p 47833 -U odoo -d MITO_DEV
|
|
```
|
|
|
|
### 2a. Pajak pada produk ongkir / delivery cost
|
|
|
|
```sql
|
|
-- Cek semua produk yang di-flag sebagai delivery cost (ongkir)
|
|
-- dan pajak penjualan (sale tax) yang terpasang.
|
|
SELECT pt.id AS tmpl_id,
|
|
pt.name->>'en_US' AS product_name,
|
|
pt.snk_delivery_cost_ok,
|
|
pt.snk_misc_exp,
|
|
array_agg(rel.account_tax_id) FILTER (WHERE rel.account_tax_id IS NOT NULL) AS sale_tax_ids
|
|
FROM product_template pt
|
|
LEFT JOIN product_taxes_rel rel ON rel.prod_id = pt.id
|
|
WHERE pt.snk_delivery_cost_ok = TRUE
|
|
GROUP BY pt.id, pt.name, pt.snk_delivery_cost_ok, pt.snk_misc_exp
|
|
ORDER BY pt.id;
|
|
```
|
|
|
|
**Interpretasi:**
|
|
- `sale_tax_ids = {NULL}` / kosong → ongkir **tanpa pajak** → akan memicu split. (kondisi dev)
|
|
- `sale_tax_ids = {<id VAT>}` → ongkir **ber-VAT** → tidak split. (kondisi lokal)
|
|
|
|
### 2b. Pajak per-baris di SO yang bermasalah
|
|
|
|
```sql
|
|
-- Ganti 'S00313' sesuai SO yang dicek.
|
|
SELECT sol.id AS line_id,
|
|
sol.sequence,
|
|
pt.name->>'en_US' AS product,
|
|
pt.snk_delivery_cost_ok,
|
|
sol.price_unit,
|
|
sol.price_subtotal,
|
|
array_agg(tr.tax_id) FILTER (WHERE tr.tax_id IS NOT NULL) AS line_tax_ids
|
|
FROM sale_order_line sol
|
|
JOIN sale_order so ON so.id = sol.order_id
|
|
LEFT JOIN product_product pp ON pp.id = sol.product_id
|
|
LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
|
|
LEFT JOIN account_tax_sale_order_line_rel tr ON tr.sale_order_line_id = sol.id
|
|
WHERE so.name = 'S00313'
|
|
GROUP BY sol.id, sol.sequence, pt.name, pt.snk_delivery_cost_ok,
|
|
sol.price_unit, sol.price_subtotal
|
|
ORDER BY sol.sequence, sol.id;
|
|
```
|
|
|
|
**Yang dicari:** baris dengan `snk_delivery_cost_ok = true` yang `line_tax_ids` kosong,
|
|
sementara baris barang punya `line_tax_ids = {VAT}`. Itu pemicu split.
|
|
|
|
### 2c. Bandingkan jumlah tax-group (kenapa dobel)
|
|
|
|
```sql
|
|
-- Berapa banyak "tax group" berbeda di SO ini?
|
|
-- Kalau > 1, discount akan dipecah sebanyak group tsb.
|
|
SELECT COALESCE(grp.tax_set, '{}') AS tax_set, COUNT(*) AS jumlah_baris
|
|
FROM (
|
|
SELECT sol.id,
|
|
array_agg(tr.tax_id ORDER BY tr.tax_id)
|
|
FILTER (WHERE tr.tax_id IS NOT NULL) AS tax_set
|
|
FROM sale_order_line sol
|
|
JOIN sale_order so ON so.id = sol.order_id
|
|
LEFT JOIN account_tax_sale_order_line_rel tr ON tr.sale_order_line_id = sol.id
|
|
WHERE so.name = 'S00313'
|
|
AND sol.display_type IS NULL -- abaikan section/note
|
|
GROUP BY sol.id
|
|
) grp
|
|
GROUP BY grp.tax_set;
|
|
```
|
|
|
|
**Interpretasi:** kalau muncul **2 baris hasil** (satu `{VAT_id}`, satu `{}`),
|
|
berarti ada 2 tax group → discount kebagi dua.
|
|
|
|
---
|
|
|
|
## 3. Tracking di LOG (`odoo.log`)
|
|
|
|
File log: `/Users/chelvynkleden/developer/SINERKA/snk_mito/config/odoo.log`
|
|
|
|
Wizard sudah punya logging detail. Kata kunci penting:
|
|
|
|
| Kata kunci | Arti |
|
|
|---|---|
|
|
| `ACTION apply_discount TRIGGERED` | User klik Apply discount |
|
|
| `Applying tiered discounts` | Masuk jalur diskon bertingkat |
|
|
| `Tier seq=` / `Tiered discount tiers:` | Daftar tier + persen |
|
|
| `Creating discount lines for tax group: original=` | **Mulai 1 tax group** — kalau muncul >1x = SPLIT |
|
|
| `Created discount line: ... Taxes: VAT` | Baris discount untuk group ber-VAT |
|
|
| `Created discount line: ... Taxes: ` (kosong) | Baris discount untuk group **ongkir tanpa pajak** ← bukti split |
|
|
|
|
### Perintah cepat
|
|
|
|
```bash
|
|
cd /Users/chelvynkleden/developer/SINERKA/snk_mito/config
|
|
|
|
# 1) Lihat semua kejadian apply discount + ringkasannya
|
|
grep -nE "ACTION apply_discount TRIGGERED|Creating discount lines for tax group|Created discount line" odoo.log
|
|
|
|
# 2) Hitung berapa tax group per apply (kalau >1 dalam satu blok = split)
|
|
grep -n "Creating discount lines for tax group" odoo.log
|
|
|
|
# 3) Cari baris discount yang Taxes-nya KOSONG (indikasi ongkir kena split)
|
|
grep -nE "Created discount line: .*Taxes: *$" odoo.log
|
|
|
|
# 4) Lihat detail satu kejadian (ganti NOMOR sesuai output di atas, ambil ±25 baris)
|
|
sed -n 'NOMOR_START,NOMOR_ENDp' odoo.log
|
|
|
|
# 5) Pantau real-time saat tes ulang di UI
|
|
tail -f odoo.log | grep --line-buffered -E "apply_discount|tax group|Created discount line"
|
|
```
|
|
|
|
### Pola log yang menandakan BUG (split)
|
|
|
|
```
|
|
🎯 Creating discount lines for tax group: original=8000000.0 <- group barang (VAT)
|
|
✅ Created discount line: Tiered Discount 11.00% - Taxes: VAT, amount=880000.0
|
|
✅ Created discount line: Tiered Discount 2.00% - Taxes: VAT, amount=142400.0
|
|
🎯 Creating discount lines for tax group: original=679000.0 <- group ONGKIR (no tax) ← MASALAH
|
|
✅ Created discount line: Tiered Discount 11.00% - Taxes: , amount=74690.0
|
|
✅ Created discount line: Tiered Discount 2.00% - Taxes: , amount=12086.2
|
|
```
|
|
|
|
### Pola log yang BENAR (tidak split)
|
|
|
|
```
|
|
🎯 Creating discount lines for tax group: original=10000000.0 <- hanya 1 group
|
|
✅ Created discount line: Tiered Discount 11.00%, amount=1100000.0
|
|
✅ Created discount line: Tiered Discount 2.00%, amount=178000.0
|
|
```
|
|
|
|
---
|
|
|
|
## 4. Kesimpulan & Rekomendasi Fix
|
|
|
|
- **Kode "berjalan sesuai yang ditulis"**, tapi **belum benar secara bisnis**:
|
|
ongkir ikut kena discount dan memicu split.
|
|
- **Root cause environment:** beda **config pajak produk ongkir** (lokal ber-VAT, dev tanpa pajak).
|
|
- **Fix yang disarankan (permanen, tidak tergantung config pajak):**
|
|
exclude baris ongkir dari target discount di
|
|
`mito/mito_base/wizards/sale/sale_order_discount.py`:
|
|
|
|
```python
|
|
target_lines = self.sale_order_id.order_line.filtered(
|
|
lambda line: line.product_uom_qty > 0 and line.price_unit > 0
|
|
and not line.product_id.snk_delivery_cost_ok # <-- exclude ongkir
|
|
)
|
|
```
|
|
|
|
Terapkan di **kedua** lokasi: `action_apply_discount()` (jalur tiered) dan
|
|
`_create_discount_lines()` (jalur global/fixed).
|
|
|
|
- **Sebelum deploy:** test di staging dengan SO yang punya barang (VAT) + ongkir
|
|
(tanpa pajak), pastikan discount hanya 1 baris per tier dan ongkir tidak terdiskon.
|