Skip to content

Commit

Permalink
[14.0][FIX] pos_order_mgmt: Return with positive amounts
Browse files Browse the repository at this point in the history
The sign of a return is forced to be negative so that it does not give
an error later when confirming the order. In addition, a confirmation
message is added in the event of returning more than the quantity sold.
  • Loading branch information
zamberjo authored and docker-odoo committed May 2, 2024
1 parent 7d515e9 commit 4893dde
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
42 changes: 42 additions & 0 deletions pos_order_mgmt/static/src/js/ProductScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright Aures Tic - Jose Zambudio <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) */
odoo.define("pos_order_mgmt.ProductScreen", function (require) {
"use strict";

const ProductScreen = require("point_of_sale.ProductScreen");
const Registries = require("point_of_sale.Registries");

const PosOrderMgmtProductScreen = (ProductScreen) =>
class extends ProductScreen {
async _onClickPay() {
if (
this.env.pos
.get_order()
.orderlines.any(
(line) =>
line.returned_orderline_id &&
Math.abs(line.quantity) > line.max_return_qty
)
) {
const {confirmed} = await this.showPopup("ConfirmPopup", {
title: this.env._t("Incorrect quantities"),
body: this.env._t(
`It is returning more than the quantity delivered.
Would you like to proceed anyway?`
),
confirmText: this.env._t("Yes"),
cancelText: this.env._t("No"),
});
if (confirmed) {
return super._onClickPay(...arguments);
}
} else {
return super._onClickPay(...arguments);
}
}
};

Registries.Component.extend(ProductScreen, PosOrderMgmtProductScreen);

return PosOrderMgmtProductScreen;
});
2 changes: 2 additions & 0 deletions pos_order_mgmt/static/src/js/RefundOrderButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ odoo.define("pos_order_mgmt.RefundOrderButton", function (require) {
merge: false,
extras: {
return_pack_lot_names: orderline.pack_lot_names,
returned_orderline_id: orderline.id,
max_return_qty: quantity,
},
});
});
Expand Down
21 changes: 19 additions & 2 deletions pos_order_mgmt/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
odoo.define("pos_order_mgmt.models", function (require) {
"use strict";

var models = require("point_of_sale.models");
const models = require("point_of_sale.models");
const field_utils = require("web.field_utils");

var _orderproto = models.Order.prototype;
const _orderproto = models.Order.prototype;
const _orderLineProto = models.Orderline.prototype;

models.Order = models.Order.extend({
init_from_JSON: function (json) {
Expand All @@ -25,4 +27,19 @@ odoo.define("pos_order_mgmt.models", function (require) {
return res;
},
});

models.Orderline = models.Orderline.extend({
set_quantity: function (quantity, keep_price) {
if (quantity !== "remove") {
quantity =
typeof quantity === "number"
? quantity
: field_utils.parse.float(String(quantity)) || 0;
if (this.returned_orderline_id) {
quantity = Math.abs(quantity) * -1;
}
}
return _orderLineProto.set_quantity.call(this, quantity, keep_price);
},
});
});
4 changes: 4 additions & 0 deletions pos_order_mgmt/views/assets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
type="text/javascript"
src="/pos_order_mgmt/static/src/js/CopyOrderButton.js"
/>
<script
type="text/javascript"
src="/pos_order_mgmt/static/src/js/ProductScreen.js"
/>
<script
type="text/javascript"
src="/pos_order_mgmt/static/src/js/RefundOrderButton.js"
Expand Down

0 comments on commit 4893dde

Please sign in to comment.