[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.
This commit is contained in:
committed by
Pierre Masereel
parent
85c11d1d40
commit
0e2aeb10af
@@ -5,15 +5,11 @@ odoo.define('l10n_fr_pos_cert.NumpadWidget', function(require) {
|
||||
const Registries = require('point_of_sale.Registries');
|
||||
|
||||
const PosFrNumpadWidget = NumpadWidget => class extends NumpadWidget {
|
||||
async changeMode(mode) {
|
||||
if (this.env.pos.is_french_country() && mode === 'price') {
|
||||
await this.showPopup('ErrorPopup', {
|
||||
title: this.env._t('Module error'),
|
||||
body: this.env._t('Adjusting the price is not allowed.'),
|
||||
});
|
||||
return;
|
||||
get hasPriceControlRights() {
|
||||
if (this.env.pos.is_french_country()) {
|
||||
return false;
|
||||
} else {
|
||||
super.changeMode(mode);
|
||||
return super.hasPriceControlRights;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
odoo.define('l10n_fr_pos_cert.ProductScreen', function(require) {
|
||||
|
||||
const ProductScreen = require('point_of_sale.ProductScreen');
|
||||
const Registries = require('point_of_sale.Registries');
|
||||
|
||||
const PosFrProductScreen = ProductScreen => class extends ProductScreen {
|
||||
disallowLineQuantityChange() {
|
||||
let result = super.disallowLineQuantityChange();
|
||||
return (this.env.pos.is_french_country() && this.numpadMode === 'quantity') || result;
|
||||
}
|
||||
};
|
||||
|
||||
Registries.Component.extend(ProductScreen, PosFrProductScreen);
|
||||
|
||||
return ProductScreen;
|
||||
});
|
||||
@@ -34,6 +34,11 @@ models.PosModel = models.PosModel.extend({
|
||||
_super_posmodel.delete_current_order.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
|
||||
disallowLineQuantityChange() {
|
||||
let result = _super_posmodel.disallowLineQuantityChange();
|
||||
return this.is_french_country() || result;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -65,10 +70,10 @@ models.Order = models.Order.extend({
|
||||
var orderline_super = models.Orderline.prototype;
|
||||
models.Orderline = models.Orderline.extend({
|
||||
can_be_merged_with: function(orderline) {
|
||||
var order = this.pos.get_order();
|
||||
var last_id = Object.keys(order.orderlines._byId)[Object.keys(order.orderlines._byId).length-1];
|
||||
let order = this.pos.get_order();
|
||||
let lastId = order.orderlines.last().cid;
|
||||
|
||||
if(this.pos.is_french_country() && (order.orderlines._byId[last_id].product.id !== orderline.product.id || order.orderlines._byId[last_id].quantity < 0)) {
|
||||
if(this.pos.is_french_country() && (order.orderlines._byId[lastId].product.id !== orderline.product.id || order.orderlines._byId[lastId].quantity < 0)) {
|
||||
return false;
|
||||
} else {
|
||||
return orderline_super.can_be_merged_with.apply(this, arguments);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<script type="text/javascript" src="/l10n_fr_pos_cert/static/src/js/pos.js"></script>
|
||||
<script type="text/javascript" src="/l10n_fr_pos_cert/static/src/js/NumpadWidget.js"></script>
|
||||
<script type="text/javascript" src="/l10n_fr_pos_cert/static/src/js/PaymentScreen.js"></script>
|
||||
<script type="text/javascript" src="/l10n_fr_pos_cert/static/src/js/ProductScreen.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -136,23 +136,22 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
|
||||
this.numpadMode = mode;
|
||||
NumberBuffer.reset();
|
||||
}
|
||||
disallowLineQuantityChange() {
|
||||
//This function will check if we should check or not the way we handle the line deletion.
|
||||
//If the localisation prevent the line deletion, this function will return true, following the override in the multiple modules.
|
||||
//By default, we'll always set the quantity according to the buffer input.
|
||||
return false;
|
||||
}
|
||||
async _updateSelectedOrderline(event) {
|
||||
if(this.disallowLineQuantityChange()) {
|
||||
if(this.numpadMode === 'quantity' && this.env.pos.disallowLineQuantityChange()) {
|
||||
let order = this.env.pos.get_order();
|
||||
let selectedLine = order.get_selected_orderline();
|
||||
let last_id = Object.keys(order.orderlines._byId)[Object.keys(order.orderlines._byId).length-1];
|
||||
let lastId = order.orderlines.last().cid;
|
||||
let currentQuantity = this.env.pos.get_order().get_selected_orderline().get_quantity();
|
||||
|
||||
if(last_id != selectedLine.cid)
|
||||
if(selectedLine.noDecrease) {
|
||||
this.showPopup('ErrorPopup', {
|
||||
title: this.env._t('Invalid action'),
|
||||
body: this.env._t('You are not allowed to change this quantity'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(lastId != selectedLine.cid)
|
||||
this._showDecreaseQuantityPopup();
|
||||
else if(currentQuantity === 1 && event.detail.buffer < 1) // Allow to put a value below 1 for the last product entry.
|
||||
this._setValue(event.detail.buffer);
|
||||
else if(currentQuantity < event.detail.buffer)
|
||||
this._setValue(event.detail.buffer);
|
||||
else if(event.detail.buffer < currentQuantity)
|
||||
@@ -231,29 +230,25 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
|
||||
async _showDecreaseQuantityPopup() {
|
||||
const { confirmed, payload: inputNumber } = await this.showPopup('NumberPopup', {
|
||||
startingValue: 0,
|
||||
title: this.env._t('Decrease the quantity by'),
|
||||
title: this.env._t('Set the new quantity'),
|
||||
});
|
||||
let decreaseQuantity = Math.abs(inputNumber);
|
||||
if (confirmed && decreaseQuantity) {
|
||||
let newQuantity = inputNumber !== ""? Math.abs(inputNumber): null;
|
||||
if (confirmed && newQuantity !== null) {
|
||||
let order = this.env.pos.get_order();
|
||||
let selectedLine = this.env.pos.get_order().get_selected_orderline();
|
||||
let currentQuantity = selectedLine.get_quantity()
|
||||
|
||||
let quantity = 0;
|
||||
order.get_orderlines().forEach(orderLine => {
|
||||
if(orderLine.get_product().id === selectedLine.get_product().id && orderLine.get_discount() === selectedLine.get_discount())
|
||||
quantity += orderLine.get_quantity();
|
||||
});
|
||||
if(currentQuantity === 1 && newQuantity > 0)
|
||||
selectedLine.set_quantity(newQuantity);
|
||||
else if(newQuantity >= currentQuantity)
|
||||
selectedLine.set_quantity(newQuantity);
|
||||
else {
|
||||
let newLine = selectedLine.clone();
|
||||
let decreasedQuantity = currentQuantity - newQuantity
|
||||
newLine.order = order;
|
||||
|
||||
if(decreaseQuantity > quantity) {
|
||||
await this.showPopup('ErrorPopup', {
|
||||
title: this.env._t('Order error'),
|
||||
body: this.env._t('Not allowed to take back more than was ordered.'),
|
||||
});
|
||||
} else {
|
||||
let decreaseLine = selectedLine.clone();
|
||||
decreaseLine.order = order;
|
||||
decreaseLine.set_quantity(-decreaseQuantity);
|
||||
order.add_orderline(decreaseLine);
|
||||
newLine.set_quantity( - decreasedQuantity);
|
||||
order.add_orderline(newLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1298,6 +1298,10 @@ exports.PosModel = Backbone.Model.extend({
|
||||
const currency = this.currency || { decimals: 2 };
|
||||
return `${Number(value.toFixed(currency.decimals || 0))}`;
|
||||
},
|
||||
|
||||
disallowLineQuantityChange() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user