refactor: filter invalid reward lines and programs in POS loyalty logic
This commit is contained in:
parent
d1bfd81554
commit
4c01b4a5e0
@ -113,6 +113,49 @@ patch(PosOrder.prototype, {
|
|||||||
return super._validForPointsCorrection(...arguments);
|
return super._validForPointsCorrection(...arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getPointsCorrection(program) {
|
||||||
|
if (!program || !program.rule_ids) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const originalLines = this.lines;
|
||||||
|
this.lines = this.lines.filter(
|
||||||
|
(line) => !(line.is_reward_line && (!line.reward_id || !line.reward_id.program_id))
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
return super._getPointsCorrection(...arguments);
|
||||||
|
} finally {
|
||||||
|
this.lines = originalLines;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_get_reward_lines() {
|
||||||
|
const rewardLines = super._get_reward_lines(...arguments);
|
||||||
|
if (!rewardLines) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return rewardLines.filter(
|
||||||
|
(line) => line.reward_id && line.reward_id.program_id
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
getOrderlines() {
|
||||||
|
const orderlines = super.getOrderlines(...arguments);
|
||||||
|
if (!orderlines) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return orderlines.filter(
|
||||||
|
(line) => !(line.is_reward_line && (!line.reward_id || !line.reward_id.program_id))
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
pointsForPrograms(programs) {
|
||||||
|
if (!programs) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const validPrograms = programs.filter((p) => p && p.rule_ids);
|
||||||
|
return super.pointsForPrograms(validPrograms);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initState — purge on next microtask after order initialization.
|
* initState — purge on next microtask after order initialization.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user