fix: add orphan reward line cleanup and implement optional chaining for program_id access in POS loyalty logic
This commit is contained in:
parent
e8e5e8d70a
commit
dfd52fe1cc
@ -361,6 +361,11 @@ patch(PosOrder.prototype, {
|
||||
const otherRewards = [];
|
||||
const paymentRewards = [];
|
||||
for (const line of otherRewardLines) {
|
||||
// Skip (and delete) orphaned reward lines where program_id is missing
|
||||
if (!line.reward_id || !line.reward_id.program_id) {
|
||||
line.delete();
|
||||
continue;
|
||||
}
|
||||
const claimedReward = {
|
||||
reward: line.reward_id,
|
||||
coupon_id: line.coupon_id?.id,
|
||||
@ -373,8 +378,8 @@ patch(PosOrder.prototype, {
|
||||
reward_identifier_code: line.reward_identifier_code,
|
||||
};
|
||||
if (
|
||||
claimedReward.reward.program_id.program_type === "gift_card" ||
|
||||
claimedReward.reward.program_id.program_type === "ewallet"
|
||||
claimedReward.reward.program_id?.program_type === "gift_card" ||
|
||||
claimedReward.reward.program_id?.program_type === "ewallet"
|
||||
) {
|
||||
paymentRewards.push(claimedReward);
|
||||
} else if (claimedReward.reward.reward_type === "product") {
|
||||
@ -418,7 +423,7 @@ patch(PosOrder.prototype, {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
claimedReward.reward.program_id.program_type === "coupons" &&
|
||||
claimedReward.reward.program_id?.program_type === "coupons" &&
|
||||
this.lines.find(
|
||||
(rewardline) => rewardline.reward_id?.id === claimedReward.reward.id
|
||||
)
|
||||
@ -428,7 +433,7 @@ patch(PosOrder.prototype, {
|
||||
if (
|
||||
claimedReward.reward.reward_product_ids?.length === 1 &&
|
||||
allRewardsMerged.filter(
|
||||
(reward) => reward.reward.program_id.id === claimedReward.reward.program_id.id
|
||||
(reward) => reward.reward.program_id?.id === claimedReward.reward.program_id?.id
|
||||
).length === 1
|
||||
) {
|
||||
delete claimedReward.args["quantity"];
|
||||
|
||||
@ -93,8 +93,8 @@ patch(ControlButtons.prototype, {
|
||||
}
|
||||
|
||||
if (
|
||||
(reward.reward_type == "product" && reward.program_id.applies_on !== "both") ||
|
||||
(reward.program_id.applies_on == "both" && potentialQty)
|
||||
(reward.reward_type == "product" && reward.program_id?.applies_on !== "both") ||
|
||||
(reward.program_id?.applies_on == "both" && potentialQty)
|
||||
) {
|
||||
const product = args["product"] || reward.reward_product_ids[0];
|
||||
await this.pos.addLineToCurrentOrder(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user