From fff2274ce14c4ed7e27f227bdb4069726d0164eb Mon Sep 17 00:00:00 2001 From: Alex Ardhian Date: Mon, 7 Sep 2026 15:47:23 +0700 Subject: [PATCH] ERP: unique index item_code, dokumentasi README, migration script update --- README.md | 19 +++++++++++++++++-- scripts/migrate_item_code.py | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3458eef..81e72b4 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,22 @@ Addon kustom dalam folder `./addons/kosbar_erp_ext/` menyediakan: --- -## 4. Struktur Database Utama (PostgreSQL) +## 4. Product Category Code & Item Code + +### Field Baru (Auto-generated): +* **Category Code** (`product.category.code`) + - 2 digit berdasarkan ID kategori + - Contoh: ID=1 → `01`, ID=7 → `07`, ID=10 → `10` + +* **Item Code** (`product.template.item_code`) + - Kombinasi: `parent_kode` (2 digit) + `kategori_kode` (2 digit) + `id_produk` (4 digit) + `nama_slug` (lowercase, tanpa spasi) + - Contoh: Kategori `05` (anak dari `01`), Produk ID=1, nama="Laptop ASUS" + - → `item_code = 01050001laptopasus` + - *Item Code otomatis diisi saat produk dibuat/diupdate.* + +--- + +## 5. Struktur Database Utama (PostgreSQL) Tabel inti Odoo 19 yang digunakan dalam alur di atas: @@ -99,7 +114,7 @@ Tabel inti Odoo 19 yang digunakan dalam alur di atas: --- -## 5. Perintah Manajemen Docker +## 6. Perintah Manajemen Docker * **Menjalankan stack:** ```bash diff --git a/scripts/migrate_item_code.py b/scripts/migrate_item_code.py index 7cca60b..8171a8a 100644 --- a/scripts/migrate_item_code.py +++ b/scripts/migrate_item_code.py @@ -1,6 +1,12 @@ import re # Migration: isi code kategori & item_code produk untuk data existing +env.cr.execute( + "CREATE UNIQUE INDEX IF NOT EXISTS product_template_item_code_uniq " + "ON product_template (item_code) WHERE item_code IS NOT NULL" +) +env.cr.commit() + cats = env['product.category'].search([]) for c in cats: if not c.code: