140 lines
6.3 KiB
Markdown
140 lines
6.3 KiB
Markdown
|
|
---
|
|||
|
|
proyek: Mesa (PT Megariamas Sentosa)
|
|||
|
|
modul: mesa
|
|||
|
|
odoo: 18.0 Enterprise
|
|||
|
|
kategori: Stock
|
|||
|
|
tanggal: 2026-10-29
|
|||
|
|
branch: krs/fix-import-transfer-duplicate-product
|
|||
|
|
commit: 02be0cc
|
|||
|
|
status: Lolos uji lokal · sudah di-push · belum PR · belum di-deploy
|
|||
|
|
tags:
|
|||
|
|
- mesa
|
|||
|
|
- stock
|
|||
|
|
- import
|
|||
|
|
- validasi
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
> Index: [[Mesa — Index]] · Kategori: **Stock**
|
|||
|
|
|
|||
|
|
# Validasi Produk Duplikat pada Import Transfer
|
|||
|
|
|
|||
|
|
**Tanggal:** 29 Oktober 2026
|
|||
|
|
**Modul:** `mesa` · file `mesa/models/stock/stock_picking.py`
|
|||
|
|
**Status:** ✅ kode selesai · ✅ lolos uji lokal · ✅ di-push ([02be0cc](https://repo.sinerka.id/SINERKA/mesa_dev/commit/02be0cc)) · ⏳ belum PR · ⏳ belum diuji di staging · ⏳ belum di-deploy
|
|||
|
|
|
|||
|
|
## Latar Belakang
|
|||
|
|
|
|||
|
|
Saat import transfer dari Excel, satu transfer bisa berisi beberapa baris dengan produk
|
|||
|
|
(internal reference) yang sama. Akibatnya terbentuk beberapa stock move untuk produk yang sama
|
|||
|
|
di satu picking. Sebelumnya **belum ada validasi apa pun** untuk ini di import transfer.
|
|||
|
|
|
|||
|
|
## Solusi
|
|||
|
|
|
|||
|
|
- [x] Penyesuaian aturan validasi dan pesan peringatan
|
|||
|
|
- [x] Saat import (tombol **Test** maupun **Import**), tidak boleh ada lebih dari 1 baris di
|
|||
|
|
Excel dengan produk (internal reference) yang sama dalam transfer yang sama
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Alur Validasi Import
|
|||
|
|
|
|||
|
|
```mermaid
|
|||
|
|
flowchart TD
|
|||
|
|
A["User upload Excel transfer<br/>(Import → Test / Import)"] --> B["base_import.execute_import<br/>(Test = dryrun, Import = commit)"]
|
|||
|
|
B --> C["stock.picking.load()<br/>Excel → 1 record per transfer<br/>(baris picking + baris line di bawahnya)"]
|
|||
|
|
C --> D["_load_records(data_list)<br/>context import_file = True"]
|
|||
|
|
D --> E["Kelompokkan line per transfer per kolom<br/>move_ids · move_ids_without_package ·<br/>move_line_ids · move_line_ids_without_package"]
|
|||
|
|
E --> F{"Ada product_id muncul<br/>lebih dari 1 baris<br/>dalam transfer yang sama?"}
|
|||
|
|
F -- "tidak" --> G["Lanjut create / update picking"]
|
|||
|
|
G --> H{"Mode?"}
|
|||
|
|
H -- "Test" --> I["Rollback, tampil 'Everything seems valid'"]
|
|||
|
|
H -- "Import" --> J["Transfer tersimpan"]
|
|||
|
|
F -- "ya, batch > 1 transfer" --> K["UserError ringkas:<br/>'Terdapat produk yang sama lebih dari 1 baris...'"]
|
|||
|
|
K --> L["Odoo ulang per transfer"]
|
|||
|
|
L --> F
|
|||
|
|
F -- "ya, per transfer" --> M["UserError rinci:<br/>'Transfer di baris 2-4: produk X muncul 2 kali (baris 2, 4)...'"]
|
|||
|
|
M --> N["Seluruh file batal<br/>(tidak ada transfer tersimpan)"]
|
|||
|
|
|
|||
|
|
classDef ok fill:#d1fae5,stroke:#059669,color:#064e3b
|
|||
|
|
classDef err fill:#fee2e2,stroke:#dc2626,color:#7f1d1d
|
|||
|
|
class I,J ok
|
|||
|
|
class K,M,N err
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Keterangan warna:** hijau = lolos validasi · merah = ditolak / import batal.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Rincian Aturan
|
|||
|
|
|
|||
|
|
- [x] Dicek per **transfer** (1 record picking di Excel = baris picking + baris line di bawahnya)
|
|||
|
|
- [x] Yang dibandingkan adalah **product id hasil konversi Odoo**. Ditulis `000-BOX000` atau
|
|||
|
|
`[000-BOX000] Nama` di Excel tetap dianggap produk yang sama.
|
|||
|
|
- [x] Berlaku untuk semua pola kolom line yang dipakai user:
|
|||
|
|
`move_ids/…`, `move_ids_without_package/…`, `move_line_ids/…`, `move_line_ids_without_package/…`
|
|||
|
|
- [x] Produk sama di **transfer berbeda** → boleh
|
|||
|
|
- [x] Satu saja error → **seluruh file batal** (perilaku bawaan `load()` Odoo), tidak ada transfer yang tersimpan setengah
|
|||
|
|
- [x] Hanya aktif saat import (`context import_file`). Input manual di form, MRP/STO, dan
|
|||
|
|
integrasi POS tidak terpengaruh.
|
|||
|
|
|
|||
|
|
## Pesan Peringatan
|
|||
|
|
|
|||
|
|
UI import Odoo **tidak menampilkan nomor baris** untuk error yang mencakup beberapa baris
|
|||
|
|
(hanya "… at multiple rows"), jadi nomor baris Excel ditulis langsung di pesan:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Terdapat produk yang sama lebih dari 1 baris dalam satu transfer. Lihat rincian baris di bawah.
|
|||
|
|
Transfer di baris 2-4: produk 000-BOX000 muncul 2 kali (baris 2, 4). Satu produk hanya boleh 1 baris per transfer, gabungkan quantity-nya.
|
|||
|
|
Transfer di baris 5-8: produk 000-COV007 muncul 3 kali (baris 6, 7, 8). Satu produk hanya boleh 1 baris per transfer, gabungkan quantity-nya.
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
- Baris pertama (ringkasan) hanya muncul kalau file berisi lebih dari 1 transfer.
|
|||
|
|
- Nomor baris = nomor baris Excel, **dengan asumsi baris 1 adalah header** dan tiap line
|
|||
|
|
menempati 1 baris berurutan. Kalau ada baris kosong di tengah satu transfer, nomor bisa meleset.
|
|||
|
|
|
|||
|
|
## Keputusan Teknis
|
|||
|
|
|
|||
|
|
| Keputusan | Alasan |
|
|||
|
|
|---|---|
|
|||
|
|
| Hook di `stock.picking._load_records` | Satu-satunya titik yang masih membawa posisi baris Excel (`info.rows`) **dan** dipanggil identik untuk Test (dryrun) maupun Import. |
|
|||
|
|
| Bukan `@api.constrains` di `stock.move` | Constraint juga kena input manual/MRP/POS, padahal di luar import produk sama bisa sah (mis. move beda grade). Pesannya juga tidak bisa menyebut baris Excel. |
|
|||
|
|
| Pesan ringkas untuk batch, rinci per transfer | `load()` mencoba batch dulu, lalu per record kalau batch gagal. Tanpa pembeda ini, rincian error muncul dobel. |
|
|||
|
|
| Tanpa migration / naik version | Hanya perubahan Python, tidak ada perubahan struktur DB. |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Hasil Uji Lokal (29 Okt 2026)
|
|||
|
|
|
|||
|
|
**Lingkungan:** docker lokal · DB `MESA_DEV` · user admin · operation type **Internal Transfers**
|
|||
|
|
(13191) · produk `000-BOX000`, `000-COV006`, `000-COV007`. Diuji lewat
|
|||
|
|
`base_import.import.execute_import` (jalur yang sama dengan UI) memakai file CSV, lalu
|
|||
|
|
**di-rollback**. DB sudah dicek bersih.
|
|||
|
|
|
|||
|
|
| Skenario | Test | Import |
|
|||
|
|
|---|---|---|
|
|||
|
|
| 2 transfer, masing-masing ada produk dobel (2× dan 3×) | ❌ ditolak, baris tepat | ❌ ditolak, 0 tersimpan |
|
|||
|
|
| 1 transfer, produk dobel | ❌ ditolak | – |
|
|||
|
|
| Tanpa dobel (produk sama tapi beda transfer) | ✅ lolos | ✅ 2 transfer tersimpan |
|
|||
|
|
| Dobel lewat kolom `move_line_ids` | ❌ ditolak | – |
|
|||
|
|
|
|||
|
|
- [x] Test (dryrun) dan Import memberi pesan yang sama
|
|||
|
|
- [x] Nomor baris di pesan cocok dengan baris Excel
|
|||
|
|
- [x] File tanpa duplikat tetap ter-import normal
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Pertanyaan Terbuka
|
|||
|
|
|
|||
|
|
- [ ] **Produk sama, lot berbeda** lewat `move_line_ids` saat ini ikut ditolak (sesuai bunyi task).
|
|||
|
|
Konfirmasi ke functional: apakah kasus beda lot seharusnya boleh?
|
|||
|
|
|
|||
|
|
## Checklist Sebelum Deploy
|
|||
|
|
|
|||
|
|
- [x] Uji lokal Test & Import (CSV, `MESA_DEV`)
|
|||
|
|
- [ ] Uji dengan file **`.xlsx` asli** dari user lewat UI (Test lalu Import)
|
|||
|
|
- [ ] Restart server Odoo (perubahan Python saja, tidak perlu `-u mesa`)
|
|||
|
|
- [x] Commit `02be0cc` di branch `krs/fix-import-transfer-duplicate-product`, sudah di-push ke origin
|
|||
|
|
- [ ] PR `krs/fix-import-transfer-duplicate-product` → `development`
|
|||
|
|
- [ ] Uji di staging
|
|||
|
|
- [ ] Deploy ke production
|