5.2 KiB
| proyek | modul | odoo | kategori | status | sumber | tags | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| Mito | snk_jobsheet_operation | 18.0 | Discount & Loyalty | Selesai — wizard manual (Plan B), version 18.0.1.0.1 | snk_mito/config/free_product_wizard.md |
|
Index: Mito — Index · Kategori: Discount & Loyalty
Free product (
buy_x_get_y) tidak bisa diandalkan lewat reward standar Odoo — mismatch poin dan discount ke-reset saat save. Plan B: wizard manual, line dibuat tanpareward_idsehingga mesin loyalty tidak pernah menyentuhnya.
Free Product Wizard — Diskon Free Product via Wizard Manual
Modul: snk_jobsheet_operation (version 18.0.1.0.1)
File terkait:
mito/snk_jobsheet_operation/wizards/snk_free_product.py→ modelsnk.free.product+snk.free.product.linemito/snk_jobsheet_operation/wizards/snk_free_product_views.xml→ form wizard + act_windowmito/snk_jobsheet_operation/views/sale_order_views.xml→ button Free Product di SOmito/snk_jobsheet_operation/security/ir.model.access.csv→ akses 2 model transientmito/snk_jobsheet_operation/wizards/__init__.py,__manifest__.py→ wiring + version
Background
Free product (program buy_x_get_y) tidak bisa diandalkan lewat mekanisme reward standar Odoo karena beberapa masalah berantai:
- Mismatch poin — rule grant
1.00 Credit per order(reward_point_mode = order), tapi reward butuh2.00 Credits. Karena_get_claimable_rewardshanya memunculkan reward jikapoints >= required_points, maka1 < 2→ reward tidak pernah muncul di wizard reward. (Modeper spentkebetulan jalan karena credit menumpuk ≥ 2.) - Discount ke-reset — kalau free product dipasang sebagai reward line (
reward_idkeisi), loyalty re-apply nilai reward (discount = 100) saat save & confirm, sehingga discount yang di-override user manual (mis. 0%) balik ke 100%.
Plan B: bikin wizard manual untuk pilih free product, bypass total mesin poin loyalty.
Root Cause (kenapa Plan B beres di akar)
Free product line dibuat sebagai line NORMAL (sale.order.line biasa) — reward_id sengaja dikosongkan.
| Masalah | Kenapa lenyap di Plan B |
|---|---|
| Mismatch poin (1 < 2) | Tidak ada cek points >= required_points sama sekali — user pilih langsung. |
| Discount ke-reset saat save/confirm | Mesin loyalty (_update_programs_and_rewards) mencari line via reward_id. Tanpa reward_id, line tidak pernah disentuh loyalty → discount tidak recalculate. |
Konsekuensi: tidak perlu hack save/restore discount. Requirement FSD "tidak recalculate kembali ketika input diskon & confirm" terpenuhi otomatis.
Alur Penggunaan
Path: Sales > Orders > Quotation/Order (state draft / sent)
- Klik button Free Product (di sebelah kanan button Reward).
- Klik Add a line:
- Urutan (
sequence) - Free Product (
reward_id) — dropdown sudah difilter (lihat tabel filter) - Product & Quantity auto-keisi dari reward, qty editable
- Urutan (
- Klik Apply → line ditambahkan ke SO:
product_id←reward.reward_product_idproduct_uom_qty←reward.reward_product_qty(editable)name="Free Product - <product>"discount=100%- tanpa
reward_id(line normal)
Filter Reward yang Muncul
Domain reward_id (via computed allowed_reward_ids):
| Kondisi | Nilai |
|---|---|
reward_type |
product |
program_id.program_type |
buy_x_get_y |
program_id.snk_state |
posted |
| AP Form | Kalau SO punya snk_ap_form → batasi ke program_id.snk_jobsheet_id in snk_ap_form. Kalau tidak ada AP Form → tampilkan semua yang posted. |
Keputusan Desain
- Line tanpa
reward_id(bukan sekadaris_reward_line = False). Yang dipakai loyalty untuk recompute adalahreward_id, bukanis_reward_line. Jadi mengosongkanreward_id= satu-satunya cara line benar-benar lepas dari mesin loyalty. - Wizard ditaruh di
snk_jobsheet_operation(bukanmito_base) karena butuhsnk_ap_form(M2M kejobsheet.operation) danloyalty.program.snk_jobsheet_id, yang keduanya hidup di modul ini. - Tidak butuh migration script — model
snk.free.product&snk.free.product.lineadalahTransientModel(tabel auto-dibuat, auto-vacuum). Cukup naikkanversiondi manifest agar file baru ter-load saat upgrade.
Catatan Upgrade
Button Free Product di-anchor ke //button[@name='action_open_reward_wizard'] (button Reward standar sale_loyalty). Jika saat -u snk_jobsheet_operation muncul error "Element ... cannot be located", ganti anchor ke action_open_discount_wizard (button Discount, pasti ada).
Test Script
| Step | Ekspektasi |
|---|---|
| 1. SO draft → isi customer, AP Form, order line (mis. WM-002 qty 5) | — |
| 2. Klik Free Product → Add a line → urutan 1 → pilih reward free product | Dropdown hanya menampilkan reward sesuai filter |
| 3. Qty auto-keisi dari reward (editable) → Apply | Line free product nongol di SO, discount 100% |
| 4. Ubah discount line free product, Save | Discount tidak balik ke 100% |
| 5. Confirm SO | Discount tetap sesuai input user (tidak recalculate) |