From 55014fdb186bc1f0a3196de3181d65bbe15c19d6 Mon Sep 17 00:00:00 2001 From: emjay0921 Date: Thu, 16 Jan 2025 12:42:26 +0800 Subject: [PATCH] [FIX] spp_pos_id_redemption: refund functionality on POS --- .../models/product_template.py | 4 +++- .../static/src/js/payment_screen.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spp_pos_id_redemption/models/product_template.py b/spp_pos_id_redemption/models/product_template.py index 55a447a0..6563ab0c 100644 --- a/spp_pos_id_redemption/models/product_template.py +++ b/spp_pos_id_redemption/models/product_template.py @@ -51,7 +51,9 @@ def redeem_voucher(self, longitude=None, latitude=None): rec.entitlement_id.longitude = longitude rec.entitlement_id.latitude = latitude - def unredeem_voucher(self): + def undo_redeem_voucher(self, longitude=None, latitude=None): for rec in self: if rec.entitlement_id: rec.entitlement_id.voucher_redeemed = False + rec.entitlement_id.longitude = longitude + rec.entitlement_id.latitude = latitude diff --git a/spp_pos_id_redemption/static/src/js/payment_screen.js b/spp_pos_id_redemption/static/src/js/payment_screen.js index b133196d..c4d88af4 100644 --- a/spp_pos_id_redemption/static/src/js/payment_screen.js +++ b/spp_pos_id_redemption/static/src/js/payment_screen.js @@ -37,8 +37,21 @@ patch(PaymentScreen.prototype, { for (const orderline of this.pos.get_order().orderlines) { if (orderline.product.created_from_entitlement) { const productId = orderline.product.id; - await this.orm.call("product.template", "redeem_voucher", [productId, latitude, longitude]); - orderline.product.voucher_redeemed = true; + if (orderline.quantity >= 1) { + await this.orm.call("product.template", "redeem_voucher", [ + productId, + latitude, + longitude, + ]); + orderline.product.voucher_redeemed = true; + } else { + await this.orm.call("product.template", "undo_redeem_voucher", [ + productId, + latitude, + longitude, + ]); + orderline.product.voucher_redeemed = false; + } } } },