[FIX] l10n_fr_pos_cert: avoid editing orders

Once an order is created in the french certification, we cannot modify
it wihout traces, so we've disabled the edtition of the order lines in
the frontend, disable the price changing, and the deletion of orders.

So when we want to decrease the quantity, a line with negative quantity
should be done.

TASK-ID: 47990
This commit is contained in:
Pierre Masereel
2019-10-01 10:02:50 +00:00
parent 5b8f86a3eb
commit 78994b55b6
2 changed files with 130 additions and 1 deletions
+6
View File
@@ -120,6 +120,12 @@ class pos_order(models.Model):
res |= super(pos_order, order).write(vals_hashing)
return res
def unlink(self):
for order in self:
if order.company_id._is_accounting_unalterable():
raise UserError(_("According to French law, you cannot delet a point of sale order."))
return super(pos_order, self).unlink()
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
+124 -1
View File
@@ -5,12 +5,28 @@ var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var rpc = require('web.rpc');
var session = require('web.session');
var core = require('web.core');
var utils = require('web.utils');
var _t = core._t;
var round_di = utils.round_decimals;
var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
is_french_country: function(){
var french_countries = ['FR', 'MF', 'MQ', 'NC', 'PF', 'RE', 'GF', 'GP', 'TF'];
return _.contains(french_countries, this.company.country.code);
}
},
delete_current_order: function () {
if (this.is_french_country() && this.get_order().get_orderlines().length) {
this.gui.show_popup("error", {
'title': _t("Fiscal Data Module error"),
'body': _t("Deleting of orders is not allowed."),
});
} else {
_super_posmodel.delete_current_order.apply(this, arguments);
}
},
});
@@ -39,6 +55,62 @@ models.Order = models.Order.extend({
}
});
var orderline_super = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
set_quantity: function (quantity, keep_price) {
var current_quantity = this.get_quantity();
var new_quantity = parseFloat(quantity) || 0;
if (this.pos.is_french_country() && (new_quantity === 0 || new_quantity < current_quantity)) {
var quantity_to_decrease = current_quantity - new_quantity;
this.pos.gui.show_popup("number", {
'title': _t("Decrease the quantity by"),
'confirm': function (qty_decrease) {
if (qty_decrease) {
var order = this.pos.get_order();
var selected_orderline = order.get_selected_orderline();
qty_decrease = parseFloat(qty_decrease);
var decimals = this.pos.dp['Product Unit of Measure'];
qty_decrease = round_di(qty_decrease, decimals);
var current_total_quantity_remaining = selected_orderline.get_quantity();
order.get_orderlines().forEach(function (orderline, index, array) {
if (selected_orderline.id != orderline.id &&
selected_orderline.get_product().id === orderline.get_product().id &&
selected_orderline.get_discount() === orderline.get_discount()) {
current_total_quantity_remaining += orderline.get_quantity();
}
});
if (qty_decrease > current_total_quantity_remaining) {
this.pos.gui.show_popup("error", {
'title': _t("Order error"),
'body': _t("Not allowed to take back more than was ordered."),
});
} else {
var decrease_line = selected_orderline.clone();
decrease_line.order = order;
orderline_super.set_quantity.apply(decrease_line, [-qty_decrease]);
order.add_orderline(decrease_line);
}
}
}
});
} else {
orderline_super.set_quantity.apply(this, arguments);
}
},
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];
if(this.pos.is_french_country() && (order.orderlines._byId[last_id].product.id !== orderline.product.id || order.orderlines._byId[last_id].quantity < 0)) {
return false;
} else {
return orderline_super.can_be_merged_with.apply(this, arguments);
}
}
});
screens.PaymentScreenWidget.include({
post_push_order_resolve: function (order, server_ids) {
@@ -70,4 +142,55 @@ screens.PaymentScreenWidget.include({
}
},
});
screens.ProductScreenWidget.include({
_onKeypadKeyDown: function (event) {
if (this.pos.is_french_country()) {
var order = this.pos.get_order();
var orderline = this.pos.get_order().selected_orderline;
var last_id = Object.keys(order.orderlines._byId)[Object.keys(order.orderlines._byId).length-1];
if( !orderline || (last_id === orderline.cid && orderline.quantity > 0)){
this._super(event);
}
} else {
this._super(event);
}
},
});
screens.NumpadWidget.include({
start: function(event) {
this._super(event);
if (this.pos.is_french_country()) {
this.$el.find('.numpad-minus').prop("disabled",true);
}
},
clickChangeMode: function (event) {
if (this.pos.is_french_country() && event.currentTarget.attributes['data-mode'].nodeValue === "price") {
this.gui.show_popup("error", {
'title': _t("Module error"),
'body': _t("Adjusting the price is not allowed."),
});
} else {
this._super(event);
}
},
clickAppendNewChar: function(event) {
if (this.pos.is_french_country()) {
var order = this.pos.get_order();
var orderline = this.pos.get_order().selected_orderline;
var last_id = Object.keys(order.orderlines._byId)[Object.keys(order.orderlines._byId).length-1];
if(last_id === orderline.cid && orderline.quantity > 0){
this._super(event);
}
} else {
this._super(event);
}
},
});
});