Browse Source

Pad improvements:

- qty change gross weight;
- accept qty <= 0, shows  warning at checkout time.
pull/501/head
François Kawala 4 years ago
parent
commit
4ddd9f67ce
  1. 6
      pos_tare/models/pos_config.py
  2. 39
      pos_tare/static/src/js/models.js
  3. 42
      pos_tare/static/src/js/screens.js

6
pos_tare/models/pos_config.py

@ -4,7 +4,8 @@ from odoo import api, models, fields
class PosConfig(models.Model):
_inherit = "pos.config"
iface_tare_method = fields.Selection([
iface_tare_method = fields.Selection(
[
("manual", "Input the tare manually"),
("barcode", "Scan a barcode to set the tare"),
("both", "Manual input and barcode"),
@ -18,7 +19,8 @@ class PosConfig(models.Model):
"* 'both' : manual input and barcode methods are enabled;",
)
iface_gross_weight_method = fields.Selection([
iface_gross_weight_method = fields.Selection(
[
("manual", "Input the Gross Weight manually"),
("scale", "Input Gross Weight via Scale")
],

39
pos_tare/static/src/js/models.js

@ -4,35 +4,8 @@ odoo.define('pos_tare.models', function (require) {
var core = require('web.core');
var models = require('point_of_sale.models');
var pos_tare_tools = require('pos_tare.tools');
var _t = core._t;
class ValidationError extends Error {
constructor(message, gui) {
super(message); // (1)
this.name = "ValidationError"; // (2)
this.gui = gui;
}
}
var _NumpadState_ = models.NumpadState.prototype;
var NumpadState = models.NumpadState.extend({
appendNewChar: function (newChar) {
try {
_NumpadState_.appendNewChar.call(this, newChar);
} catch (error) {
if (error instanceof ValidationError) {
var title = _t("Error while applying the numpad action");
var popup = {title: title, body: error.message};
error.gui.show_popup('error', popup);
_NumpadState_.deleteLastChar.call(this);
} else {
throw error;
}
}
},
});
var _super_ = models.Orderline.prototype;
var OrderLineWithTare = models.Orderline.extend({
@ -95,16 +68,6 @@ odoo.define('pos_tare.models', function (require) {
this.pos, tare_in_product_uom, line_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 ValidationError(_.str.sprintf(
_t("The tare weight is %s %s, it's greater or equal" +
" to the gross weight %s. To apply this tare would" +
" result in a negative net weight and a negative" +
" price. This tare can not be applied to this item."),
tare_in_product_uom_string, line_unit.name,
this.get_quantity_str_with_unit()), this.pos.gui);
}
// Update the quantity with the new weight net of tare quantity.
this.set_quantity(net_quantity);
}
@ -148,8 +111,6 @@ odoo.define('pos_tare.models', function (require) {
});
models.NumpadState = NumpadState;
models.Orderline = OrderLineWithTare;
});

42
pos_tare/static/src/js/screens.js

@ -7,6 +7,7 @@ odoo.define('pos_tare.screens', function (require) {
var _t = core._t;
var round_pr = utils.round_precision;
var leq_zero_qty = (ol) => ol.get_quantity() <= 0;
// This configures read action for tare barcode. A tare barcode contains a
// fake product ID and the weight to be subtracted from the product in the
@ -133,13 +134,44 @@ odoo.define('pos_tare.screens', function (require) {
});
screens.PaymentScreenWidget.include({
validate_order: function(options) {
var order = this.pos.get_order();
var orderlines = Array.from(order.get_orderlines());
if (orderlines.some(leq_zero_qty)) {
var _super_validate_order = this._super.bind(this);
var wrong_orderline = orderlines.find(leq_zero_qty);
var wrong_product = wrong_orderline.get_product().display_name;
this.gui.show_popup('confirm', {
title: _t('Quantity lower or equal to zero'),
body: _.str.sprintf(
_t("The quantity for \"%s\" is lower or equal to" +
" zero. Call for help unless your perfectly sure " +
" about what you are doing."), wrong_product),
confirm: function() {
_super_validate_order();
},
});
return;
}
return this._super(options);
},
});
screens.OrderWidget.include({
set_value: function (val) {
var order = this.pos.get_order();
if (order.get_selected_orderline()) {
var mode = this.numpad_state.get('mode');
if (mode === 'quantity') {
order.get_selected_orderline().set_quantity(val);
var orderline = order.get_selected_orderline();
var tare = orderline.get_tare();
orderline.reset_tare();
orderline.set_quantity(val);
if (tare > 0) {
orderline.set_tare(tare, true);
}
} else if (mode === 'discount') {
order.get_selected_orderline().set_discount(val);
} else if (mode === 'price') {
@ -155,7 +187,13 @@ odoo.define('pos_tare.screens', function (require) {
' you have to change the tare input method' +
' in the POS configuration.')});
} else {
order.get_selected_orderline().set_tare(val, true);
try {
order.get_selected_orderline().set_tare(val, true);
} catch (error) {
var title = _t("We can not apply this tare.");
var popup = {title: title, body: error.message};
this.gui.show_popup('error', popup);
}
}
}
}

Loading…
Cancel
Save