diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-08-21 10:19:29 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-08-21 10:19:29 +0000 |
| commit | bc2614bf4f8b2eba30491dd2adf2b6812444f906 (patch) | |
| tree | 2c736349df426ead38efff787211081bd0272a01 | |
| parent | fc6f0a00ab98a72ad3d08f1d5ad6f8120e21814a (diff) | |
| parent | 2ce13e5d71a1f1c1bebaa45e596ad52eb55f9e8f (diff) | |
<Miqdad> Block keyboard input check product
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/static/src/js/check_product_barcode.js | 97 |
3 files changed, 69 insertions, 32 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 95989c79..360303b8 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -10,8 +10,8 @@ 'images': ['assets/favicon.ico'], 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan', 'vit_efaktur'], 'data': [ + 'views/assets.xml', 'security/ir.model.access.csv', - # 'views/assets.xml', 'views/group_partner.xml', 'views/blog_post.xml', 'views/coupon_program.xml', diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 7e970c5d..a48e0ed1 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -2072,6 +2072,8 @@ class CheckProduct(models.Model): _name = 'check.product' _description = 'Check Product' _order = 'picking_id, id' + _inherit = ['barcodes.barcode_events_mixin'] + picking_id = fields.Many2one( 'stock.picking', diff --git a/indoteknik_custom/static/src/js/check_product_barcode.js b/indoteknik_custom/static/src/js/check_product_barcode.js index 9da41479..2fddc616 100644 --- a/indoteknik_custom/static/src/js/check_product_barcode.js +++ b/indoteknik_custom/static/src/js/check_product_barcode.js @@ -1,41 +1,76 @@ -odoo.define('indoteknik_custom.prevent_manual_typing', function (require) { - "use strict"; +odoo.define('indoteknik_custom.buffered_scanner', function (require) { + 'use strict'; + console.log('✅ Indoteknik_Custom JS Loaded'); - console.log("✅ Custom JS from indoteknik_custom loaded!"); + var GAP_MS = 120; + var MIN_LEN = 3; + var COMMIT_TIMEOUT = 180; + var buffer = ''; + var last = 0; + var timer = null; - const THRESHOLD_MS = 300; - let lastTime = 0; - let burstCount = 0; + function reset() { + buffer = ''; + last = 0; + if (timer) { clearTimeout(timer); timer = null; } + } - function isScannerLike(now) { - const gap = now - lastTime; - lastTime = now; - if (gap < THRESHOLD_MS) { - burstCount += 1; - } else { - burstCount = 1; - } - return burstCount >= 2; + function isCodeProduct(el) { + return el && el instanceof HTMLInputElement && el.name === 'code_product'; + } + + function commit() { + var el = document.activeElement; + if (!isCodeProduct(el)) { reset(); return; } + if (buffer.length >= MIN_LEN) { + el.value = buffer; + el.dispatchEvent(new Event('input', { bubbles: true })); + el.dispatchEvent(new Event('change', { bubbles: true })); + } + reset(); + } + + document.addEventListener('keydown', function (e) { + var el = document.activeElement; + if (!isCodeProduct(el)) return; + + var key = e.key; + + // ENTER mengakhiri scan + if (key === 'Enter') { + e.preventDefault(); + commit(); + return; } - document.addEventListener('keydown', function (e) { - const t = e.target; - if (!(t instanceof HTMLInputElement)) return; + // abaikan tombol kontrol (Shift, Tab, Arrow, Backspace, dll.) + if (key.length !== 1) return; - // pastikan hanya field code_product - if (t.name !== 'code_product') return; + var now = performance.now(); + var gap = now - (last || now); + last = now; - const now = performance.now(); - const scanner = isScannerLike(now); + if (!buffer || gap <= GAP_MS) { + // bagian dari "scan cepat" → tangani sendiri (hindari karakter hilang) + e.preventDefault(); + buffer += key; - // enter tetap boleh (scanner biasanya akhiri Enter) - if (e.key === "Enter") return; + if (timer) clearTimeout(timer); + timer = setTimeout(function () { + // auto-commit jika scanner tidak mengirim Enter + commit(); + }, COMMIT_TIMEOUT); + } else { + // jeda besar → kemungkinan manual. Kalau mau benar-benar melarang, + // buka komentar 2 baris di bawah. + // e.preventDefault(); + // e.stopPropagation(); + reset(); // keluar dari mode buffer agar manual normal + } + }, true); - // kalau bukan scanner → blok manual ketikan - if (!scanner) { - e.preventDefault(); - e.stopPropagation(); - } - }, true); -}); + document.addEventListener('focusin', function (e) { + if (isCodeProduct(e.target)) reset(); + }, true); +});
\ No newline at end of file |
