From 96a5d6e6e78eee218053cb443cc253a125498611 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 19 May 2020 16:40:35 +0200 Subject: [PATCH] [FIX] do not make a substraction when call set_tare in the ScaleScreen. (otherwise, the tare is reduced two times). [ADD] possibility to set manually the gross weight, if the scale doesn't work --- pos_tare/models/pos_config.py | 21 +++++++++++++++------ pos_tare/static/src/js/models.js | 25 ++++++++++++++----------- pos_tare/static/src/js/screens.js | 19 ++++++++++++++++--- pos_tare/static/src/xml/pos_tare.xml | 14 ++++++++++++-- pos_tare/views/view_pos_config.xml | 15 ++++++++++++++- 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/pos_tare/models/pos_config.py b/pos_tare/models/pos_config.py index 01595485..68e9bf56 100644 --- a/pos_tare/models/pos_config.py +++ b/pos_tare/models/pos_config.py @@ -2,15 +2,15 @@ from odoo import api, models, fields class PosConfig(models.Model): - _inherit = 'pos.config' + _inherit = "pos.config" iface_tare_method = fields.Selection([ - ('manual', 'Input the tare manually'), - ('barcode', 'Scan a barcode to set the tare'), - ('both', 'Manual input and barcode'), + ("manual", "Input the tare manually"), + ("barcode", "Scan a barcode to set the tare"), + ("both", "Manual input and barcode"), ], - string='Tare input method', - default='both', + string="Tare Input Method", + default="both", required=True, help="Select tare method:\n" "* 'manual' : the scale screen has an extra tare input field;\n" @@ -18,6 +18,15 @@ class PosConfig(models.Model): "* 'both' : manual input and barcode methods are enabled;", ) + iface_gross_weight_method = fields.Selection([ + ("manual", "Input the Gross Weight manually"), + ("scale", "Input Gross Weight via Scale") + ], + string="Gross Weight Input Method", + default="scale", + required=True, + ) + iface_tare_uom_id = fields.Many2one( string="Unit of Measure of the tare", comodel_name="uom.uom", diff --git a/pos_tare/static/src/js/models.js b/pos_tare/static/src/js/models.js index 31a66844..2c73c792 100644 --- a/pos_tare/static/src/js/models.js +++ b/pos_tare/static/src/js/models.js @@ -44,7 +44,7 @@ odoo.define('pos_tare.models', function (require) { // ///////////////////////////// // Custom Section // ///////////////////////////// - set_tare: function (quantity) { + set_tare: function (quantity, update_net_weight) { this.order.assert_editable(); // Prevent to apply multiple times a tare to the same product. @@ -64,20 +64,23 @@ odoo.define('pos_tare.models', function (require) { var tare_in_product_uom = pos_tare_tools.convert_mass(tare, tare_unit, line_unit); var tare_in_product_uom_string = pos_tare_tools.format_tare(this.pos, tare_in_product_uom, line_unit); - var net_quantity = this.get_quantity() - tare_in_product_uom; - // This method fails when the net weight is negative. - if (net_quantity <= 0) { - throw new RangeError(_.str.sprintf( - _t("The tare weight is %s %s, it's greater or equal to " + - "the product weight %s. We can not apply this tare."), - tare_in_product_uom_string, line_unit.name, - this.get_quantity_str_with_unit())); + if (update_net_weight) { + var net_quantity = this.get_quantity() - tare_in_product_uom; + // This method fails when the net weight is negative. + if (net_quantity <= 0) { + throw new RangeError(_.str.sprintf( + _t("The tare weight is %s %s, it's greater or equal to " + + "the product weight %s. We can not apply this tare."), + tare_in_product_uom_string, line_unit.name, + this.get_quantity_str_with_unit())); + } + // Update the quantity with the new weight net of tare quantity. + this.set_quantity(net_quantity); } // Update tare value. this.tare = tare_in_product_uom; - // Update the quantity with the new weight net of tare quantity. - this.set_quantity(net_quantity); this.trigger('change', this); + }, get_tare: function () { diff --git a/pos_tare/static/src/js/screens.js b/pos_tare/static/src/js/screens.js index a5fde269..38ba1321 100644 --- a/pos_tare/static/src/js/screens.js +++ b/pos_tare/static/src/js/screens.js @@ -18,7 +18,7 @@ odoo.define('pos_tare.screens', function (require) { var order = this.pos.get_order(); var selected_order_line = order.get_selected_orderline(); var tare_weight = code.value; - selected_order_line.set_tare(tare_weight); + selected_order_line.set_tare(tare_weight, true); } catch (error) { var title = _t("We can not apply this tare barcode."); var popup = {title: title, body: error.message}; @@ -51,7 +51,15 @@ odoo.define('pos_tare.screens', function (require) { this.$('#input_weight_tare').keyup(function (event) { self.onchange_tare(event); }); - this.$('#input_weight_tare').focus(); + this.$('#input_gross_weight').keyup(function (event) { + self.onchange_gross_weight(event); + }); + if (this.pos.config.iface_gross_weight_method === 'scale') { + this.$('#input_weight_tare').focus(); + } else{ + this.pos.proxy_queue.clear(); + this.$('#input_gross_weight').focus(); + } }, // Overload set_weight function @@ -79,7 +87,7 @@ odoo.define('pos_tare.screens', function (require) { if (this.tare > 0.0) { var order = this.pos.get_order(); var orderline = order.get_last_orderline(); - orderline.set_tare(this.tare); + orderline.set_tare(this.tare, false); } } }, @@ -110,6 +118,11 @@ odoo.define('pos_tare.screens', function (require) { this.set_weight(this.gross_weight); }, + onchange_gross_weight: function () { + var gross_weight = this.check_sanitize_value('#input_gross_weight'); + this.set_weight(gross_weight); + }, + check_sanitize_value: function (input_name) { var res = this.$(input_name)[0].value.replace(',', '.').trim(); if (isNaN(res)) { diff --git a/pos_tare/static/src/xml/pos_tare.xml b/pos_tare/static/src/xml/pos_tare.xml index 34dc8e32..af3edb28 100644 --- a/pos_tare/static/src/xml/pos_tare.xml +++ b/pos_tare/static/src/xml/pos_tare.xml @@ -8,12 +8,22 @@
Gross Weight
-
+ +
+ + +
+ + +
+
Tare
- Kg + +
diff --git a/pos_tare/views/view_pos_config.xml b/pos_tare/views/view_pos_config.xml index 8e6e667a..11ca9424 100644 --- a/pos_tare/views/view_pos_config.xml +++ b/pos_tare/views/view_pos_config.xml @@ -11,7 +11,7 @@
-
+
+
+
+