[FIX] pos_loyalty: correct value for gift card with discount
Current behavior: When you sell a gift card in the PoS with a discount, the value of the gift card is not correct. For example, if you sell a gift card of 100€ with a 50% discount the customer should pay 50€ and the gift card should be worth 100€. But the customer pays 50€ and the gift card is worth 50€. Steps to reproduce: - Create a gift card program - Open a PoS session - Sell a gift card of 100€ with a 50% discount - Pay the order - The value of the giftcard should be 100€ but it is 50€ opw-3221553 closes odoo/odoo#116746 X-original-commit: 1631ab332a6c9c7ca5e1f2451a51fb663534cb8e Signed-off-by: Trinh Jacky (trj) <trj@odoo.com> Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
@@ -378,10 +378,15 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
wait_for_push_order() {
|
||||
return (
|
||||
!_.isEmpty(this.couponPointChanges) ||
|
||||
this._has_gift_card_product() ||
|
||||
this._get_reward_lines().length ||
|
||||
this._super(...arguments)
|
||||
);
|
||||
},
|
||||
_has_gift_card_product() {
|
||||
const orderLines = this.get_orderlines();
|
||||
return orderLines.some((line) => line.eWalletGiftCardProgram);
|
||||
},
|
||||
/**
|
||||
* Add additional information for our ticket, such as new coupons and loyalty point gains.
|
||||
*
|
||||
@@ -925,8 +930,12 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let price_to_use = line.get_price_with_tax();
|
||||
if (program.program_type === 'gift_card') {
|
||||
price_to_use = line.price;
|
||||
}
|
||||
const pointsPerUnit = round_precision(
|
||||
(rule.reward_point_amount * line.get_price_with_tax()) /
|
||||
(rule.reward_point_amount * price_to_use) /
|
||||
line.get_quantity(),
|
||||
0.01
|
||||
);
|
||||
|
||||
@@ -49,3 +49,14 @@ PosLoyalty.check.orderTotalIs("35.00");
|
||||
PosLoyalty.exec.finalizeOrder("Cash", "35");
|
||||
registry.category("web_tour.tours").add("GiftCardProgramScanUseTour", { test: true, url: "/pos/web", steps: getSteps() });
|
||||
//#endregion
|
||||
|
||||
//#region GiftCardProgramCreateSetTour1
|
||||
startSteps();
|
||||
ProductScreen.do.confirmOpeningPopup();
|
||||
ProductScreen.do.clickHomeCategory();
|
||||
ProductScreen.do.clickDisplayedProduct('Gift Card');
|
||||
ProductScreen.do.pressNumpad('Disc 5 0');
|
||||
PosLoyalty.check.orderTotalIs('25.00');
|
||||
PosLoyalty.exec.finalizeOrder('Cash', '25');
|
||||
registry.category('web_tour.tours').add('GiftCardWithDiscountTour', { test: true, url: '/pos/web', steps: getSteps() });
|
||||
//#endregion
|
||||
|
||||
@@ -815,3 +815,26 @@ class TestUi(TestPointOfSaleHttpCommon):
|
||||
"PosLoyaltyFreeProductTour2",
|
||||
login="accountman",
|
||||
)
|
||||
|
||||
def test_gift_card_value_with_discount(self):
|
||||
"""When selling a gift card with a discount, the value of the gift card
|
||||
should be the amount before the discount."""
|
||||
LoyaltyProgram = self.env['loyalty.program']
|
||||
# Deactivate all other programs to avoid interference
|
||||
(LoyaltyProgram.search([])).write({'pos_ok': False})
|
||||
# But activate the gift_card_product_50 and ewallet_product_50 because they're shared among new programs.
|
||||
self.env.ref('loyalty.gift_card_product_50').write({'active': True})
|
||||
self.env.ref('loyalty.ewallet_product_50').write({'active': True})
|
||||
# Create programs
|
||||
programs = self.create_programs([
|
||||
('gift_card_1', 'gift_card'),
|
||||
])
|
||||
# Run the tour to topup ewallets.
|
||||
self.start_tour(
|
||||
"/pos/web?config_id=%d" % self.main_pos_config.id,
|
||||
"GiftCardWithDiscountTour",
|
||||
login="accountman",
|
||||
)
|
||||
# Check the created gift cards.
|
||||
self.assertEqual(len(programs['gift_card_1'].coupon_ids), 1)
|
||||
self.assertEqual(programs['gift_card_1'].coupon_ids.points, 50)
|
||||
|
||||
Reference in New Issue
Block a user