diff options
| -rwxr-xr-x | fixco_custom/__manifest__.py | 1 | ||||
| -rw-r--r-- | fixco_custom/static/src/js/check_product_barcode.js | 76 | ||||
| -rw-r--r-- | fixco_custom/views/assets.xml | 7 |
3 files changed, 84 insertions, 0 deletions
diff --git a/fixco_custom/__manifest__.py b/fixco_custom/__manifest__.py index 5d9a65a..b6d5aec 100755 --- a/fixco_custom/__manifest__.py +++ b/fixco_custom/__manifest__.py @@ -10,6 +10,7 @@ 'images': ['assets/favicon.ico'], 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'proweb_kartu_stok', 'base_accounting_kit'], 'data': [ + 'views/assets.xml', 'security/ir.model.access.csv', 'views/res_partner.xml', 'views/sale_order.xml', diff --git a/fixco_custom/static/src/js/check_product_barcode.js b/fixco_custom/static/src/js/check_product_barcode.js new file mode 100644 index 0000000..38a9a59 --- /dev/null +++ b/fixco_custom/static/src/js/check_product_barcode.js @@ -0,0 +1,76 @@ +odoo.define('indoteknik_custom.buffered_scanner', function (require) { + 'use strict'; + console.log('✅ Mqdd_Custom JS Loaded'); + + var GAP_MS = 120; + var MIN_LEN = 3; + var COMMIT_TIMEOUT = 180; + + var buffer = ''; + var last = 0; + var timer = null; + + function reset() { + buffer = ''; + last = 0; + if (timer) { clearTimeout(timer); timer = null; } + } + + function isCodeProduct(el) { + return el && el instanceof HTMLInputElement && (el.name === 'code_product' || el.name === 'quantity'); + } + + 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; + } + + // abaikan tombol kontrol (Shift, Tab, Arrow, Backspace, dll.) + if (key.length !== 1) return; + + var now = performance.now(); + var gap = now - (last || now); + last = now; + + if (!buffer || gap <= GAP_MS) { + // bagian dari "scan cepat" → tangani sendiri (hindari karakter hilang) + e.preventDefault(); + buffer += key; + + 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); + + document.addEventListener('focusin', function (e) { + if (isCodeProduct(e.target)) reset(); + }, true); +});
\ No newline at end of file diff --git a/fixco_custom/views/assets.xml b/fixco_custom/views/assets.xml new file mode 100644 index 0000000..2ecfe3f --- /dev/null +++ b/fixco_custom/views/assets.xml @@ -0,0 +1,7 @@ +<odoo> + <template id="indoteknik_assets_backend" inherit_id="web.assets_backend" name="Mqdd Custom Backend Assets"> + <xpath expr="." position="inside"> + <script type="text/javascript" src="/fixco_custom/static/src/js/check_product_barcode.js"/> + </xpath> + </template> +</odoo> |
