Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] pos_order_mgmt: Return with positive amounts #1067

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <jose@aurestic.es>
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
Loading