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 otherRewards = [];
|
||||||
const paymentRewards = [];
|
const paymentRewards = [];
|
||||||
for (const line of otherRewardLines) {
|
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 = {
|
const claimedReward = {
|
||||||
reward: line.reward_id,
|
reward: line.reward_id,
|
||||||
coupon_id: line.coupon_id?.id,
|
coupon_id: line.coupon_id?.id,
|
||||||
@ -373,8 +378,8 @@ patch(PosOrder.prototype, {
|
|||||||
reward_identifier_code: line.reward_identifier_code,
|
reward_identifier_code: line.reward_identifier_code,
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
claimedReward.reward.program_id.program_type === "gift_card" ||
|
claimedReward.reward.program_id?.program_type === "gift_card" ||
|
||||||
claimedReward.reward.program_id.program_type === "ewallet"
|
claimedReward.reward.program_id?.program_type === "ewallet"
|
||||||
) {
|
) {
|
||||||
paymentRewards.push(claimedReward);
|
paymentRewards.push(claimedReward);
|
||||||
} else if (claimedReward.reward.reward_type === "product") {
|
} else if (claimedReward.reward.reward_type === "product") {
|
||||||
@ -418,7 +423,7 @@ patch(PosOrder.prototype, {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
claimedReward.reward.program_id.program_type === "coupons" &&
|
claimedReward.reward.program_id?.program_type === "coupons" &&
|
||||||
this.lines.find(
|
this.lines.find(
|
||||||
(rewardline) => rewardline.reward_id?.id === claimedReward.reward.id
|
(rewardline) => rewardline.reward_id?.id === claimedReward.reward.id
|
||||||
)
|
)
|
||||||
@ -428,7 +433,7 @@ patch(PosOrder.prototype, {
|
|||||||
if (
|
if (
|
||||||
claimedReward.reward.reward_product_ids?.length === 1 &&
|
claimedReward.reward.reward_product_ids?.length === 1 &&
|
||||||
allRewardsMerged.filter(
|
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
|
).length === 1
|
||||||
) {
|
) {
|
||||||
delete claimedReward.args["quantity"];
|
delete claimedReward.args["quantity"];
|
||||||
|
|||||||
@ -93,8 +93,8 @@ patch(ControlButtons.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(reward.reward_type == "product" && reward.program_id.applies_on !== "both") ||
|
(reward.reward_type == "product" && reward.program_id?.applies_on !== "both") ||
|
||||||
(reward.program_id.applies_on == "both" && potentialQty)
|
(reward.program_id?.applies_on == "both" && potentialQty)
|
||||||
) {
|
) {
|
||||||
const product = args["product"] || reward.reward_product_ids[0];
|
const product = args["product"] || reward.reward_product_ids[0];
|
||||||
await this.pos.addLineToCurrentOrder(
|
await this.pos.addLineToCurrentOrder(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user