summaryrefslogtreecommitdiff
path: root/addons/pos_restaurant/static
diff options
context:
space:
mode:
authorRobin Heinz <rhe@odoo.com>2020-04-02 11:20:10 +0000
committerPierre Masereel <pim@odoo.com>2020-05-12 12:52:23 +0000
commit0e2aeb10af8b48312e1335865298e636cd29c1e2 (patch)
tree6bac007b83b99f708669de64f98ce1589ef5bb71 /addons/pos_restaurant/static
parent85c11d1d40b5b54527fae5856c5884f4ad48fe7a (diff)
[IMP] point_of_sale,l10n_fr_pos_cert,pos_restaurant: new set quantity
For most localizations, decreasing quantity of an orderline is prohibited. This commit generalizes this behavior and is now available in core point_of_sale.
Diffstat (limited to 'addons/pos_restaurant/static')
-rw-r--r--addons/pos_restaurant/static/src/js/Screens/SplitBillScreen/SplitBillScreen.js79
1 files changed, 56 insertions, 23 deletions
diff --git a/addons/pos_restaurant/static/src/js/Screens/SplitBillScreen/SplitBillScreen.js b/addons/pos_restaurant/static/src/js/Screens/SplitBillScreen/SplitBillScreen.js
index 1c5613b3166..2390e35f7c4 100644
--- a/addons/pos_restaurant/static/src/js/Screens/SplitBillScreen/SplitBillScreen.js
+++ b/addons/pos_restaurant/static/src/js/Screens/SplitBillScreen/SplitBillScreen.js
@@ -85,28 +85,36 @@ odoo.define('pos_restaurant.SplitBillScreen', function(require) {
_initSplitLines(order) {
const splitlines = {};
for (let line of order.get_orderlines()) {
- splitlines[line.id] = { quantity: 0 };
+ splitlines[line.id] = { product: line.get_product().id, quantity: 0 };
}
return splitlines;
}
_splitQuantity(line) {
const split = this.splitlines[line.id];
- if (!line.get_unit().is_pos_groupable) {
- if (split.quantity !== line.get_quantity()) {
- split.quantity = line.get_quantity();
- } else {
- split.quantity = 0;
- }
- } else {
- if (split.quantity < line.get_quantity()) {
- split.quantity += line.get_unit().is_pos_groupable
- ? 1
- : line.get_unit().rounding;
- if (split.quantity > line.get_quantity()) {
+
+ let totalQuantity = 0;
+
+ this.env.pos.get_order().get_orderlines().forEach(function(orderLine) {
+ if(orderLine.get_product().id === split.product)
+ totalQuantity += orderLine.get_quantity();
+ });
+
+ if(line.get_quantity() > 0) {
+ if (!line.get_unit().is_pos_groupable) {
+ if (split.quantity !== line.get_quantity()) {
split.quantity = line.get_quantity();
+ } else {
+ split.quantity = 0;
}
} else {
- split.quantity = 0;
+ if (split.quantity < totalQuantity) {
+ split.quantity += line.get_unit().is_pos_groupable? 1: line.get_unit().rounding;
+ if (split.quantity > line.get_quantity()) {
+ split.quantity = line.get_quantity();
+ }
+ } else {
+ split.quantity = 0;
+ }
}
}
}
@@ -126,21 +134,46 @@ odoo.define('pos_restaurant.SplitBillScreen', function(require) {
}
}
_isFullPayOrder() {
- return _.every(this.currentOrder.get_orderlines(), orderLine => {
- var split = this.splitlines[orderLine.id];
- return split && split.quantity === orderLine.get_quantity();
+ let order = this.env.pos.get_order();
+ let full = true;
+ let splitlines = this.splitlines;
+ let groupedLines = _.groupBy(order.get_orderlines(), line => line.get_product().id);
+
+ Object.keys(groupedLines).forEach(function (lineId) {
+ var maxQuantity = groupedLines[lineId].reduce(((quantity, line) => quantity + line.get_quantity()), 0);
+ Object.keys(splitlines).forEach(id => {
+ let split = splitlines[id];
+ if(split.product === groupedLines[lineId][0].get_product().id)
+ maxQuantity -= split.quantity;
+ });
+ if(maxQuantity !== 0)
+ full = false;
});
+
+ return full;
}
_setQuantityOnCurrentOrder() {
+ let order = this.env.pos.get_order();
for (var id in this.splitlines) {
var split = this.splitlines[id];
var line = this.currentOrder.get_orderline(parseInt(id));
- line.set_quantity(
- line.get_quantity() - split.quantity,
- 'do not recompute unit price'
- );
- if (Math.abs(line.get_quantity()) < 0.00001) {
- this.currentOrder.remove_orderline(line);
+
+ if(!this.props.disallow) {
+ line.set_quantity(
+ line.get_quantity() - split.quantity,
+ 'do not recompute unit price'
+ );
+ if (Math.abs(line.get_quantity()) < 0.00001) {
+ this.currentOrder.remove_orderline(line);
+ }
+ } else {
+ if(split.quantity) {
+ let decreaseLine = line.clone();
+ decreaseLine.order = order;
+ decreaseLine.noDecrease = true;
+ decreaseLine.set_quantity(-split.quantity);
+ order.add_orderline(decreaseLine);
+ }
}
}
}