summaryrefslogtreecommitdiff
path: root/fixco_custom/static/src
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-03-02 14:50:03 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-03-02 14:50:03 +0700
commit73e1e2d09375d7ac632fec6512b143942beb6b35 (patch)
treeff428ff5f294a9675cd2bd13aa22ed269eaf3e5a /fixco_custom/static/src
parent91ebd47ad05518ceafd5af798e295700ed0296d2 (diff)
<Miqdad> prevent user to add product manually in check product
Diffstat (limited to 'fixco_custom/static/src')
-rw-r--r--fixco_custom/static/src/js/check_product_barcode.js76
1 files changed, 76 insertions, 0 deletions
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