[FIX] pos_loyalty: check expired promo code
Create an expired loyalty program with code Open POS session Add product Apply code Issue: code is applied even if expired opw-3624670 closes odoo/odoo#145609 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -533,6 +533,20 @@ msgstr ""
|
||||
msgid "That promo code program has already been activated."
|
||||
msgstr ""
|
||||
|
||||
#. module: pos_loyalty
|
||||
#. odoo-javascript
|
||||
#: code:addons/pos_loyalty/static/src/overrides/models/loyalty.js:0
|
||||
#, python-format
|
||||
msgid "That promo code program is expired."
|
||||
msgstr ""
|
||||
|
||||
#. module: pos_loyalty
|
||||
#. odoo-javascript
|
||||
#: code:addons/pos_loyalty/static/src/overrides/models/loyalty.js:0
|
||||
#, python-format
|
||||
msgid "That promo code program is not yet valid."
|
||||
msgstr ""
|
||||
|
||||
#. module: pos_loyalty
|
||||
#. odoo-javascript
|
||||
#: code:addons/pos_loyalty/static/src/overrides/models/loyalty.js:0
|
||||
|
||||
@@ -7,6 +7,7 @@ import { _t } from "@web/core/l10n/translation";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup";
|
||||
|
||||
const { DateTime } = luxon;
|
||||
const mutex = new Mutex(); // Used for sequential cache updates
|
||||
const updateRewardsMutex = new Mutex();
|
||||
|
||||
@@ -695,10 +696,10 @@ patch(Order.prototype, {
|
||||
if (program.is_nominative && !this.get_partner()) {
|
||||
return false;
|
||||
}
|
||||
if (program.date_from && program.date_from > new Date()) {
|
||||
if (program.date_from && program.date_from.startOf('day') > DateTime.now()) {
|
||||
return false;
|
||||
}
|
||||
if (program.date_to && program.date_to < new Date()) {
|
||||
if (program.date_to && program.date_to.endOf('day') < DateTime.now()) {
|
||||
return false;
|
||||
}
|
||||
if (program.limit_usage && program.total_order_count >= program.max_usage) {
|
||||
@@ -1508,6 +1509,12 @@ patch(Order.prototype, {
|
||||
let claimableRewards = null;
|
||||
let coupon = null;
|
||||
if (rule) {
|
||||
if (rule.program_id.date_from && this.date_order < rule.program_id.date_from.startOf("day")) {
|
||||
return _t("That promo code program is not yet valid.");
|
||||
}
|
||||
if (rule.program_id.date_to && this.date_order > rule.program_id.date_to.endOf("day")) {
|
||||
return _t("That promo code program is expired.")
|
||||
}
|
||||
const program_pricelists = rule.program_id.pricelist_ids;
|
||||
if (
|
||||
program_pricelists.length > 0 &&
|
||||
|
||||
@@ -9,6 +9,7 @@ import { TextInputPopup } from "@point_of_sale/app/utils/input_popups/text_input
|
||||
import { Domain, InvalidDomainError } from "@web/core/domain";
|
||||
import { PosLoyaltyCard } from "@pos_loyalty/overrides/models/loyalty";
|
||||
|
||||
const { DateTime } = luxon;
|
||||
const COUPON_CACHE_MAX_SIZE = 4096; // Maximum coupon cache size, prevents long run memory issues and (to some extent) invalid data
|
||||
|
||||
patch(PosStore.prototype, {
|
||||
@@ -278,8 +279,11 @@ patch(PosStore.prototype, {
|
||||
|
||||
for (const program of this.programs) {
|
||||
this.program_by_id[program.id] = program;
|
||||
if (program.date_from) {
|
||||
program.date_from = DateTime.fromISO(program.date_from);
|
||||
}
|
||||
if (program.date_to) {
|
||||
program.date_to = new Date(program.date_to);
|
||||
program.date_to = DateTime.fromISO(program.date_to);
|
||||
}
|
||||
program.rules = [];
|
||||
program.rewards = [];
|
||||
|
||||
Reference in New Issue
Block a user