Browse Source

[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

pull/501/head
Sylvain LE GAL 4 years ago
parent
commit
96a5d6e6e7
  1. 21
      pos_tare/models/pos_config.py
  2. 25
      pos_tare/static/src/js/models.js
  3. 19
      pos_tare/static/src/js/screens.js
  4. 14
      pos_tare/static/src/xml/pos_tare.xml
  5. 15
      pos_tare/views/view_pos_config.xml

21
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",

25
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 () {

19
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)) {

14
pos_tare/static/src/xml/pos_tare.xml

@ -8,12 +8,22 @@
<div class="weight-label">
Gross Weight
</div>
<div class="weight-value weight-value-fixed" id="container_weight_gross"/>
<t t-if="widget.pos.config.iface_gross_weight_method == 'scale'">
<div class="weight-value weight-value-fixed"
id="container_weight_gross"/>
</t>
<t t-else="1">
<div class="weight-value weight-value-alterable">
<input type="text" class="input-weight" id="input_gross_weight" placeholder="0.000"/>
<t t-esc="widget.pos.config.iface_tare_uom_id[1]"/>
</div>
</t>
<div class="weight-label">
Tare
</div>
<div class="weight-value weight-value-alterable">
<input type="text" class="input-weight" id="input_weight_tare" placeholder="0.000"/> Kg
<input type="text" class="input-weight" id="input_weight_tare" placeholder="0.000"/>
<t t-esc="widget.pos.config.iface_tare_uom_id[1]"/>
</div>
</t>
</t>

15
pos_tare/views/view_pos_config.xml

@ -11,7 +11,7 @@
<xpath expr="//h2[@name='order']/following-sibling::*[position()=1]" position="inside">
<div class="col-xs-12 col-lg-6 o_setting_box" id="iface_tare_method">
<div class="o_setting_right_pane">
<label for="iface_tare_method" string="Tare method"/>
<label for="iface_tare_method" string="Tare Input Method"/>
<div class="text-muted">
Configure how to tare products to weight with a scale.
</div>
@ -35,6 +35,19 @@
</div>
</div>
</div>
<div class="col-xs-12 col-lg-6 o_setting_box" id="iface_gross_weight_method">
<div class="o_setting_right_pane">
<label for="iface_gross_weight_method" string="Gross Weight Input Method"/>
<div class="text-muted">
Configure how to input Gross Weight.
</div>
<div class="content-group">
<div class="mt16">
<field name="iface_gross_weight_method" class="o_light_label"/>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>

Loading…
Cancel
Save