mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
feat: reset used coupon count after canceling or returning an invoice
This commit is contained in:
parent
5f86cc8ff2
commit
301a04a638
@ -195,6 +195,9 @@ export abstract class Invoice extends Transactional {
|
||||
|
||||
if (this.isReturn) {
|
||||
await this._removeLoyaltyPointEntry();
|
||||
await this.reduceUsedCountOfCoupons();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isQuote) {
|
||||
@ -248,12 +251,14 @@ export abstract class Invoice extends Transactional {
|
||||
await this._updatePartyOutStanding();
|
||||
await this._updateIsItemsReturned();
|
||||
await this._removeLoyaltyPointEntry();
|
||||
await this._reduceUsedCountOfCoupon();
|
||||
}
|
||||
|
||||
async _reduceUsedCountOfCoupon() {
|
||||
await this.reduceUsedCountOfCoupons();
|
||||
}
|
||||
|
||||
async _removeLoyaltyPointEntry() {
|
||||
if (!this.loyaltyProgram) {
|
||||
return;
|
||||
}
|
||||
await removeLoyaltyPoint(this);
|
||||
}
|
||||
|
||||
@ -567,6 +572,20 @@ export abstract class Invoice extends Transactional {
|
||||
await couponDoc.setAndSync({ used: (couponDoc.used as number) + 1 });
|
||||
});
|
||||
}
|
||||
async reduceUsedCountOfCoupons() {
|
||||
if (!this.coupons?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.coupons?.map(async (coupon) => {
|
||||
const couponDoc = await this.fyo.doc.getDoc(
|
||||
ModelNameEnum.CouponCode,
|
||||
coupon.coupons
|
||||
);
|
||||
|
||||
await couponDoc.setAndSync({ used: (couponDoc.used as number) - 1 });
|
||||
});
|
||||
}
|
||||
|
||||
async _updateIsItemsReturned() {
|
||||
if (!this.isReturn || !this.returnAgainst || this.isQuote) {
|
||||
|
@ -762,6 +762,10 @@ export function getLoyaltyProgramTier(
|
||||
}
|
||||
|
||||
export async function removeLoyaltyPoint(doc: Doc) {
|
||||
if (!doc.loyaltyProgram) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = (await doc.fyo.db.getAll(ModelNameEnum.LoyaltyPointEntry, {
|
||||
fields: ['name', 'loyaltyPoints', 'expiryDate'],
|
||||
filters: {
|
||||
|
Loading…
Reference in New Issue
Block a user