summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/__manifest__.py3
-rw-r--r--indoteknik_custom/models/stock_picking.py17
-rw-r--r--indoteknik_custom/static/src/js/check_product_barcode.js41
-rw-r--r--indoteknik_custom/views/assets.xml7
4 files changed, 67 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index d1ae681a..85603a33 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -8,9 +8,10 @@
'author': 'Rafi Zadanly',
'website': '',
'images': ['assets/favicon.ico'],
- 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan', 'vit_efaktur' ],
+ 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan', 'vit_efaktur', 'barcodes'],
'data': [
'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 cb36eb2f..3d04a416 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -2070,6 +2070,8 @@ class CheckProduct(models.Model):
_name = 'check.product'
_description = 'Check Product'
_order = 'picking_id, id'
+ _inherit = ['barcodes.barcode_events_mixin'] # ⬅️ aktifkan barcode handler
+
picking_id = fields.Many2one(
'stock.picking',
@@ -2084,6 +2086,21 @@ class CheckProduct(models.Model):
status = fields.Char(string='Status', compute='_compute_status')
code_product = fields.Char(string='Code Product')
+ def write(self, vals):
+ if 'code_product' in vals and not self.env.context.get('from_barcode_scan'):
+ raise UserError("Field Code Product hanya bisa diisi melalui barcode scan.")
+ res = super().write(vals)
+ # konsolidasi dll milik Anda tetap jalan
+ if not self.env.context.get('skip_consolidate'):
+ self.with_context(skip_consolidate=True)._consolidate_duplicate_lines()
+ return res
+
+ # Scanner handler
+ def on_barcode_scanned(self, barcode):
+ self.ensure_one()
+ self.with_context(from_barcode_scan=True).write({'code_product': barcode})
+ self._onchange_code_product()
+
@api.onchange('code_product')
def _onchange_code_product(self):
if not self.code_product:
diff --git a/indoteknik_custom/static/src/js/check_product_barcode.js b/indoteknik_custom/static/src/js/check_product_barcode.js
new file mode 100644
index 00000000..f7a1bb75
--- /dev/null
+++ b/indoteknik_custom/static/src/js/check_product_barcode.js
@@ -0,0 +1,41 @@
+odoo.define('indoteknik_custom.prevent_manual_typing', function (require) {
+ "use strict";
+
+ console.log("✅ Custom JS from indoteknik_custom loaded!");
+
+
+ const THRESHOLD_MS = 40; // jeda antar karakter dianggap scanner kalau <40ms
+ let lastTime = 0;
+ let burstCount = 0;
+
+ function isScannerLike(now) {
+ const gap = now - lastTime;
+ lastTime = now;
+ if (gap < THRESHOLD_MS) {
+ burstCount += 1;
+ } else {
+ burstCount = 1;
+ }
+ return burstCount >= 3; // setelah 3 char cepat, dianggap scanner
+ }
+
+ document.addEventListener('keydown', function (e) {
+ const t = e.target;
+ if (!(t instanceof HTMLInputElement)) return;
+
+ // pastikan hanya field code_product
+ if (t.name !== 'code_product') return;
+
+ const now = performance.now();
+ const scanner = isScannerLike(now);
+
+ // enter tetap boleh (scanner biasanya akhiri Enter)
+ if (e.key === "Enter") return;
+
+ // kalau bukan scanner → blok manual ketikan
+ if (!scanner) {
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ }, true);
+});
diff --git a/indoteknik_custom/views/assets.xml b/indoteknik_custom/views/assets.xml
new file mode 100644
index 00000000..4475004e
--- /dev/null
+++ b/indoteknik_custom/views/assets.xml
@@ -0,0 +1,7 @@
+<odoo>
+ <template id="indoteknik_assets_backend" inherit_id="web.assets_backend" name="Indoteknik Custom Backend Assets">
+ <xpath expr="." position="inside">
+ <script type="text/javascript" src="/indoteknik_custom/static/src/js/check_product_barcode.js"/>
+ </xpath>
+ </template>
+</odoo>