From d05ce6239803d052d30c1ec9f4fbdf14dc0525ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Kawala?= Date: Wed, 5 Feb 2020 09:07:44 +0100 Subject: [PATCH] Define a "tare" barcode type instead of hijacking the weight type. --- pos_barcode_tare/models/__init__.py | 3 ++- pos_barcode_tare/models/barcode_rule.py | 14 +++++++++++ pos_barcode_tare/models/pos_config.py | 9 ------- pos_barcode_tare/readme/USAGE.rst | 2 +- .../static/src/js/pos_barcode_tare.js | 24 ++++++++++--------- pos_barcode_tare/views/pos_config_view.xml | 12 ++++++++-- 6 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 pos_barcode_tare/models/barcode_rule.py diff --git a/pos_barcode_tare/models/__init__.py b/pos_barcode_tare/models/__init__.py index f7dd4ebc..77bf99d8 100644 --- a/pos_barcode_tare/models/__init__.py +++ b/pos_barcode_tare/models/__init__.py @@ -1 +1,2 @@ -from . import pos_config \ No newline at end of file +from . import pos_config +from . import barcode_rule \ No newline at end of file diff --git a/pos_barcode_tare/models/barcode_rule.py b/pos_barcode_tare/models/barcode_rule.py new file mode 100644 index 00000000..8da0d8fc --- /dev/null +++ b/pos_barcode_tare/models/barcode_rule.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from openerp import _, models, fields, api + + +class BarcodeRule(models.Model): + _inherit = 'barcode.rule' + + @api.model + def _get_type_selection(self): + res = super(BarcodeRule, self)._get_type_selection() + res.append( + ('tare', _('Tare'))) + return res \ No newline at end of file diff --git a/pos_barcode_tare/models/pos_config.py b/pos_barcode_tare/models/pos_config.py index 380cfbfb..c6756101 100644 --- a/pos_barcode_tare/models/pos_config.py +++ b/pos_barcode_tare/models/pos_config.py @@ -9,12 +9,3 @@ class PosConfig(models.Model): 'Show tare label button', help="Print tare labels with this POS" ) - - iface_tare_barcode_sequence_id = fields.Integer( - 'Barcode nomenclature sequence ID', - default=36, - required=True, - help="""The nomenclature ID gives barcode pattern. - It can be found in POS Barcode Nomenclatures. The expected barcode - pattern is 21.....{NNDDD}""" - ) diff --git a/pos_barcode_tare/readme/USAGE.rst b/pos_barcode_tare/readme/USAGE.rst index a57f2807..f50bb306 100644 --- a/pos_barcode_tare/readme/USAGE.rst +++ b/pos_barcode_tare/readme/USAGE.rst @@ -1,4 +1,4 @@ -Install this add-on and configure the point of sale where you want to be able to use the tare barecode. Setup the default barcode sequence ID according to your barcode nomenclature. The barcode pattern should be ``XX.....NNDDD`` where XX is the barcode prefix. In the default barcode nomenclature, the weight barcode pattern sequence id is 36 and its prefix is 21. The label printing is done using web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or the kiosk printing (chrome). +Install this add-on and configure the point of sale where you want to be able to use the tare barecode. The label printing is done using web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or the kiosk printing (chrome). The command line to start a chrome base browser in kiosk mode with silent printing looks like: diff --git a/pos_barcode_tare/static/src/js/pos_barcode_tare.js b/pos_barcode_tare/static/src/js/pos_barcode_tare.js index d52d838c..d2b676ed 100644 --- a/pos_barcode_tare/static/src/js/pos_barcode_tare.js +++ b/pos_barcode_tare/static/src/js/pos_barcode_tare.js @@ -12,6 +12,7 @@ odoo.define('pos_barcode_tare.screens', function (require) { var QWeb = core.qweb; var _t = core._t; var round_pr = utils.round_precision; + var tare_barcode_type = "tare"; // Define functions used to do unit operation. // Get unit search for unit based on unit name. @@ -54,7 +55,7 @@ odoo.define('pos_barcode_tare.screens', function (require) { // latest order line. screens.ScreenWidget.include( { - barcode_weight_action: function (code) { + barcode_tare_action: function (code) { var order = this.pos.get_order(); // Computes the paid weight var last_order_line = order.get_last_orderline(); @@ -95,8 +96,8 @@ odoo.define('pos_barcode_tare.screens', function (require) { show: function () { this._super(); this.pos.barcode_reader.set_action_callback( - 'weight', - _.bind(this.barcode_weight_action, this)); + 'tare', + _.bind(this.barcode_tare_action, this)); }, }); @@ -132,8 +133,7 @@ odoo.define('pos_barcode_tare.screens', function (require) { // Fetch the unit of measure used to save the tare this.kg_unit = get_unit(this.pos, "kg"); // Fetch the barcode prefix from POS barcode parser rules. - this.weight_barcode_prefix = this.get_barcode_prefix( - this.pos.config.iface_tare_barcode_sequence_id); + this.weight_barcode_prefix = this.get_barcode_prefix(); // Setup the proxy var queue = this.pos.proxy_queue; // The pooling of the scale starts here. @@ -148,15 +148,17 @@ odoo.define('pos_barcode_tare.screens', function (require) { this.render_receipt(); this.lock_screen(true); }, - get_barcode_prefix: function (barcode_sequence_id) { - var barcode_pattern = this.get_barcode_pattern(barcode_sequence_id); + get_barcode_prefix: function () { + var barcode_pattern = this.get_barcode_pattern(); return barcode_pattern.substr(0, 2); }, - get_barcode_pattern: function (barcode_sequence_id) { + get_barcode_pattern: function () { var rules = this.get_barcode_rules(); var rule = rules.filter( function (r) { - return r.sequence === barcode_sequence_id; + // We select the first (smallest sequence ID) barcode rule + // with the expected type. + return r.type === tare_barcode_type; })[0]; return rule.pattern; }, @@ -191,8 +193,8 @@ odoo.define('pos_barcode_tare.screens', function (require) { return checksum % 10; }, barcode_data: function (weight) { - // We use EAN13 barcode, it looks like 21 00000 12345 x. First there - // is the prefix, here 21, that is used to decide which type of + // We use EAN13 barcode, it looks like 07 00000 12345 x. First there + // is the prefix, here 07, that is used to decide which type of // barcode we're dealing with. A weight barcode has then two groups // of five digits. The first group encodes the product id. Here the // product id is 00000. The second group encodes the weight in diff --git a/pos_barcode_tare/views/pos_config_view.xml b/pos_barcode_tare/views/pos_config_view.xml index 924ecd05..cbfb762b 100644 --- a/pos_barcode_tare/views/pos_config_view.xml +++ b/pos_barcode_tare/views/pos_config_view.xml @@ -1,6 +1,6 @@ - + pos.config @@ -9,9 +9,17 @@ - + + + Tare + + 81 + tare + ean13 + 0700000{NNDDD} +