diff options
| author | Joren Van Onder <jov@odoo.com> | 2016-02-17 11:44:39 +0100 |
|---|---|---|
| committer | Antony Lesuisse <al@openerp.com> | 2016-03-17 09:39:18 +0100 |
| commit | 5bb64d40d0b94b252c2e29e6a050ae37fbd87b0f (patch) | |
| tree | e3b25b152c345f05633970e889339311f0e4ef49 | |
| parent | c6fc91b3182d1651c0326ba2f491f659457b4497 (diff) | |
[IMP] barcodes: allow immediate quantity input after scanning
When scanning items with a device like the Symbol MC3200 you are
presented with the Kanban view because of it's limited resolution.
In this view it is not possible to quickly set the quantity of scanned
products. Ideally users just want to scan the barcode, input the
quantity and repeat without having to click on virtual buttons on the
usually less than ideal touchscreen.
This implements a way for users to immediately start typing numbers
representing a quantity after scanning a barcode. The quantity will be
set on the specified m2x_field.quantity_field of the record associated
to the last scanned barcode. Because KanbanRecords are not editable
without opening a new view window.prompt is used. It will create an easy
to use native dialog of whatever device is being used. It also avoids us
having to implement a custom input field which would have to handle
keypress events like numbers, backspace, delete, etc.
| -rw-r--r-- | addons/barcodes/i18n/barcodes.pot | 25 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/form_view_barcode_handler.js | 69 |
2 files changed, 90 insertions, 4 deletions
diff --git a/addons/barcodes/i18n/barcodes.pot b/addons/barcodes/i18n/barcodes.pot index 248fdaac767..1d2c7ad4a2b 100644 --- a/addons/barcodes/i18n/barcodes.pot +++ b/addons/barcodes/i18n/barcodes.pot @@ -143,12 +143,19 @@ msgstr "" #. module: barcodes #. openerp-web -#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:51 +#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:122 #, python-format msgid "Error : Document not editable" msgstr "" #. module: barcodes +#. openerp-web +#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:56 +#, python-format +msgid "Error : No last scanned barcode" +msgstr "" + +#. module: barcodes #: model:ir.model.fields,field_description:barcodes.field_barcode_nomenclature_id #: model:ir.model.fields,field_description:barcodes.field_barcode_rule_id #: model:ir.model.fields,field_description:barcodes.field_barcodes_barcode_events_mixin_id @@ -210,6 +217,13 @@ msgid "Sequence" msgstr "" #. module: barcodes +#. openerp-web +#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:68 +#, python-format +msgid "Set quantity" +msgstr "" + +#. module: barcodes #: model:ir.ui.view,arch_db:barcodes.view_barcode_nomenclature_form msgid "Tables" msgstr "" @@ -244,12 +258,19 @@ msgstr "" #. module: barcodes #. openerp-web -#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:51 +#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:122 #, python-format msgid "To modify this document, please first start edition." msgstr "" #. module: barcodes +#. openerp-web +#: code:addons/barcodes/static/src/js/form_view_barcode_handler.js:56 +#, python-format +msgid "To set the quantity please scan a barcode first." +msgstr "" + +#. module: barcodes #: model:ir.model.fields,field_description:barcodes.field_barcode_rule_type msgid "Type" msgstr "" diff --git a/addons/barcodes/static/src/js/form_view_barcode_handler.js b/addons/barcodes/static/src/js/form_view_barcode_handler.js index ac5a74e554c..572913c1b54 100644 --- a/addons/barcodes/static/src/js/form_view_barcode_handler.js +++ b/addons/barcodes/static/src/js/form_view_barcode_handler.js @@ -23,6 +23,13 @@ KanbanRecord.include({ }); var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { + init: function(parent, context) { + this.__quantity_listener = _.bind(this._set_quantity_listener, this); + BarcodeHandlerMixin.init.apply(this, arguments); + + return this._super.apply(this, arguments); + }, + start: function() { this._super(); this.form_view = this.field_manager; @@ -44,7 +51,64 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { this.map_barcode_method['O-CMD.PAGER-NEXT'] = _.bind(this.form_view.pager.next, this.form_view.pager); } }, - + + _display_no_edit_mode_warning: function() { + this.do_warn(_t('Error : Document not editable'), _t('To modify this document, please first start edition.')); + }, + + _display_no_last_scanned_warning: function() { + this.do_warn(_t('Error : No last scanned barcode'), _t('To set the quantity please scan a barcode first.')); + }, + + _set_quantity_listener: function(event) { + var self = this; + var character = String.fromCharCode(event.which); + + if (this.form_view.get('actual_mode') === 'view') { + this._display_no_edit_mode_warning(); + } else if ($(event.target).is('body') && /[0-9]/.test(character)) { // only catch the event if we're not focused in + // another field and it's a number + var field = this.form_view.fields[this.m2x_field]; + var view = field.viewmanager.active_view; + + if (this.last_scanned_barcode) { + var new_qty = window.prompt(_t('Set quantity'), character) || "0"; + new_qty = new_qty.replace(',', '.'); + var record = this._get_records(field).find(function(record) { + return record.get('product_barcode') === self.last_scanned_barcode; + }); + if (record) { + var values = {}; + values[this.quantity_field] = parseFloat(new_qty); + field.data_update(record.get('id'), values).then(function () { + view.controller.reload_record(record); + }); + } else { + this._display_no_last_scanned_warning(); + } + } else { + this._display_no_last_scanned_warning(); + } + } + }, + + start_listening: function() { + if (this.quantity_field && ! this.is_listening) { + core.bus.on('keypress', this, this.__quantity_listener); + } + + BarcodeHandlerMixin.start_listening.call(this); + }, + + stop_listening: function() { + if (this.quantity_field && this.is_listening) { + core.bus.off('keypress', this, this.__quantity_listener); + delete this.last_scanned_barcode; + } + + BarcodeHandlerMixin.stop_listening.call(this); + }, + // Let subclasses add custom behaviour before onchange. Must return a deferred. // Resolve the deferred with true proceed with the onchange, false to prevent it. pre_onchange_hook: function(barcode) { @@ -53,6 +117,7 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { on_barcode_scanned: function(barcode) { var self = this; + self.last_scanned_barcode = barcode; // Execute a harcoded action var action = this.map_barcode_method[barcode]; if (typeof action === "function") @@ -61,7 +126,7 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { return; // Warn the user if form view is not editable else if (this.form_view.get('actual_mode') === 'view') - this.do_warn(_t('Error : Document not editable'), _t('To modify this document, please first start edition.')); + this._display_no_edit_mode_warning(); else { // Call hook method possibly implemented by subclass this.pre_onchange_hook(barcode).then(function(proceed) { |
