95 lines
5.7 KiB
Markdown
95 lines
5.7 KiB
Markdown
|
|
---
|
||
|
|
judul: SFA CMS — Sync Customer dari Odoo
|
||
|
|
proyek: SFA CMS
|
||
|
|
terkait: Mito · Odoo 18 · mito_base
|
||
|
|
stack: Laravel 11 · Filament 3 · Odoo 18 REST API (mito_base)
|
||
|
|
kategori: Integrasi
|
||
|
|
status: Ter-deploy di VPS (develop 8d5f815) 2026-10-06 — cron aktif
|
||
|
|
tipe: dokumen-internal
|
||
|
|
tags:
|
||
|
|
- sfa
|
||
|
|
- cms
|
||
|
|
- odoo
|
||
|
|
- integrasi
|
||
|
|
- scheduler
|
||
|
|
- master-customer
|
||
|
|
diperbarui: 2026-10-06
|
||
|
|
---
|
||
|
|
|
||
|
|
> Index: [[SFA — Index]] · Kategori: **Integrasi**
|
||
|
|
>
|
||
|
|
> Pasangan dari [[SFA CMS — Sync Master Product dari Odoo]]. Client API, auth, masalah
|
||
|
|
> `no_database`, `.env`, dan langkah deploy **sama persis**; dokumen ini hanya mencatat
|
||
|
|
> yang khusus untuk customer.
|
||
|
|
|
||
|
|
# Sync Customer Odoo → SFA-CMS
|
||
|
|
|
||
|
|
## 1. Ringkasan
|
||
|
|
|
||
|
|
| | |
|
||
|
|
|---|---|
|
||
|
|
| **Sumber** | `GET /api/v1/customers` dari `mito_base` (`res.partner` tipe contact) |
|
||
|
|
| **Yang di-sync** | Hanya `status = validate` → **1.259 customer** (dari 2.205; 946 draft kebanyakan data sampah: nama karyawan `[00] …`, nomor HP, dll) |
|
||
|
|
| **Kunci** | Kolom lama `customer.cust_code` = id `res.partner` Odoo (string, mis. `9483`). **Tidak ada kolom/tabel baru** |
|
||
|
|
| **Data lama CMS** | Dihapus (soft delete) — **834** customer lama. Master customer sekarang murni dari Odoo |
|
||
|
|
| **Command** | `php artisan odoo:sync-customers` (`--dry-run`, `--since=`) |
|
||
|
|
| **Jadwal** | Harian **01:15 WIB** (15 menit setelah sync product) · log `storage/logs/odoo-sync-customers.log` |
|
||
|
|
| **Hasil uji lokal** | `created=1259 deleted=834`, run berikutnya `unchanged=1259 deleted=0`, tanpa duplikat |
|
||
|
|
| **Server (dry-run 06-10-2026)** | `created=1259 deleted=836` — semua customer uji di server di-soft delete. Lihat [[SFA CMS — Deploy 2026-10-06]] |
|
||
|
|
|
||
|
|
File: `app/Console/Commands/SyncOdooCustomers.php` + jadwal di `routes/console.php`.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 2. Mapping Field
|
||
|
|
|
||
|
|
| Odoo API | CMS `customer` | Catatan |
|
||
|
|
|---|---|---|
|
||
|
|
| `id` | `cust_code` | **Kunci sync**. Number sequence `CUST` tidak dipakai |
|
||
|
|
| `name` | `cust_name` | Maks 60 karakter |
|
||
|
|
| `initial_name` | `shop_name` | Nama toko, mis. `TOKO ABADI ELEKTRONIK / ABADI MAKMUR MANDIRI` |
|
||
|
|
| `is_company` | `cust_type` | `COMPANY` / `INDIVIDUAL` |
|
||
|
|
| `status` | `cust_status` | Selalu `ACTIVE` (yang di-sync hanya `validate`) |
|
||
|
|
| `phone` (fallback `mobile`) | `phone_number` | Maks 20 karakter |
|
||
|
|
| `email` | `email_address` | |
|
||
|
|
| `address.street, street2, city, state, zip` | `cust_address` | Digabung pakai koma |
|
||
|
|
| `area.name` | `area_id` + `area_code` | Ambil bagian sebelum ` - `: `SURABAYA - GUDANG DEPO …` → `SURABAYA`, dicocokkan ke `area.description` / `area_code` |
|
||
|
|
| `channel.name` | `channel_id` + `channel_code` | Dicocokkan ke `channel_code` / `description` |
|
||
|
|
| `grade.name` | `customer_grade_id` + `customer_grade_code` | A/B/C cocok ke master yang ada |
|
||
|
|
| `salesperson.name` | `employee_id` + `empl_code` | Prefix `[00] ` dibuang, dicocokkan ke `employee.empl_name`. **Tidak membuat employee baru** |
|
||
|
|
|
||
|
|
Kolom yang **tidak disentuh** sync: `longitude`, `latitude`, `radius`, `credit_limit`,
|
||
|
|
`term_of_payment_*`, `wh_*`, `legal_entity_id`, `pkp`, `vat_num`, `discount`, `pic`,
|
||
|
|
`cust_category`, dll. Nilai yang diisi dari CMS/mobile (mis. titik GPS) tidak tertimpa.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 3. Aturan Sync
|
||
|
|
|
||
|
|
| Kondisi | Aksi |
|
||
|
|
|---|---|
|
||
|
|
| `cust_code` belum ada | **Create** |
|
||
|
|
| Ada & berubah | **Update** |
|
||
|
|
| Ada & tidak berubah | Dilewati |
|
||
|
|
| Soft-deleted & muncul lagi di Odoo | **Restore** |
|
||
|
|
| Tidak ada di hasil Odoo (data lama, customer di-draft/archive di Odoo) | **Soft delete**, hanya saat full sync |
|
||
|
|
| Customer hasil **Customer Registration** CMS (`customer_registration.customer_id`) | **Tidak dihapus** walaupun belum ada di Odoo |
|
||
|
|
| Odoo mengembalikan 0 customer | Soft delete dilewati (anomali) |
|
||
|
|
|
||
|
|
Soft delete → histori SO, kunjungan, task, dan invoice lama tetap utuh.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 4. Temuan & Catatan Terbuka
|
||
|
|
|
||
|
|
| # | Temuan | Dampak / Saran |
|
||
|
|
|---|---|---|
|
||
|
|
| 1 | API customer **tidak mengirim kode customer** (`ref` & `short_code` kosong di semua 2.205 record) | Terpaksa pakai id Odoo sebagai `cust_code`. Kalau Odoo nanti punya kode customer resmi, mapping bisa diganti |
|
||
|
|
| 2 | Kode area/channel CMS (`SBY`, `DLDI`, `SMOO`) ≠ Odoo (`SURABAYA - GUDANG DEPO …`, `GT`, `SC`) | Sync membuat **37 master baru** (area: GELAEL, SHOPEE, TOKOPEDIA, ASC MEDAN, …; channel: GT, SC, RESELLER, PROMOSI, …). Perlu keputusan: rapikan di Odoo atau buat tabel mapping |
|
||
|
|
| 3 | Salesperson: 42 nama di Odoo, **29 cocok** ke employee CMS | 13 sisanya (`Bimo Firgiawan`, `Alvian Alieffikry`, …) → `employee_id` kosong. Daftarkan employee-nya di CMS dengan nama sama, sync berikutnya otomatis terisi |
|
||
|
|
| 4 | 206 customer validate tanpa area, 509 tanpa salesperson | Perlu dilengkapi di Odoo |
|
||
|
|
| 5 | Customer Registration CMS belum terhubung ke Odoo | Customer hasil registrasi tetap ada di CMS tapi tidak ada di Odoo. Perlu alur kirim ke Odoo (belum ada endpoint `POST /customers`) |
|
||
|
|
| 6 | Menu Customer di Filament masih bisa create/edit | Customer yang dibuat manual akan ter-soft delete di sync berikutnya. Saran: read-only, kecuali via Customer Registration |
|
||
|
|
| 7 | 🔴 **Prospect dari SFA Mobile ikut terhapus tiap malam** | `POST /master/customer` (sfa-api) membuat customer `PROSPECT` dengan `cust_code` number sequence. Full sync men-soft delete semua `cust_code` yang bukan id Odoo (kecuali hasil registrasi) → prospect hilang dari aplikasi esok harinya (`Mcustomer` paranoid). Opsi: batasi soft delete ke `cust_code` numerik (asal Odoo), atau kecualikan `cust_category = PROSPECT`. **Putuskan sebelum production** |
|
||
|
|
| 8 | Sync membuat baris baru, bukan mengadopsi baris lama | Saat pertama jalan, transaksi lama (SO, kunjungan, `invent_trans`) tetap menunjuk ke customer/produk lama yang di-soft delete. Aman untuk server yang masih data uji; kalau ada data sungguhan perlu pemetaan (Odoo tidak punya `ref`/`short_code` → hanya lewat nama/HP) |
|