diff --git a/models/baseModels/Invoice/Invoice.ts b/models/baseModels/Invoice/Invoice.ts index bc8ee68e..ebae8586 100644 --- a/models/baseModels/Invoice/Invoice.ts +++ b/models/baseModels/Invoice/Invoice.ts @@ -87,7 +87,6 @@ export abstract class Invoice extends Transactional { stockNotTransferred?: number; loyaltyProgram?: string; backReference?: string; - originalGrandTotal?: Money; submitted?: boolean; cancelled?: boolean; makeAutoPayment?: boolean; @@ -262,15 +261,6 @@ export abstract class Invoice extends Transactional { this.reduceUsedCountOfCoupons(); } - async grandTotalLpa() { - if (!this.originalGrandTotal) { - this.originalGrandTotal = this.grandTotal; - } - - const amountAfterPoints = await this.getLPAddedBaseGrandTotal(); - this.grandTotal = amountAfterPoints; - } - async _removeLoyaltyPointEntry() { await removeLoyaltyPoint(this); } @@ -447,10 +437,6 @@ export abstract class Invoice extends Transactional { }, (this.netTotal as Money).abs()) .sub(totalDiscount); - if (this.originalGrandTotal && !this.redeemLoyaltyPoints) { - grandTotal = this.originalGrandTotal; - } - return grandTotal; } @@ -758,7 +744,7 @@ export abstract class Invoice extends Transactional { this.loyaltyPoints as number ); - return this.originalGrandTotal?.sub(totalLotaltyAmount); + return this.grandTotal?.sub(totalLotaltyAmount); } formulas: FormulaMap = { diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index 53e8f28e..d1d16b62 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -42,7 +42,6 @@ export class Payment extends Transactional { referenceType?: ModelNameEnum.SalesInvoice | ModelNameEnum.PurchaseInvoice; for?: PaymentFor[]; _accountsMap?: AccountTypeMap; - initialAmount?: Money; async paymentMethodDoc() { return (await this.loadAndGetLink('paymentMethod')) as PaymentMethod; @@ -704,25 +703,17 @@ export class Payment extends Transactional { return; } - if (!this.initialAmount) { - this.initialAmount = this.amount as Money; - } + const amount = (this.getSum('for', 'amount', false) as Money).abs(); - const moneyValue = value as Money; - - if (moneyValue.gt(this.initialAmount)) { + if ((value as Money).gt(amount)) { throw new ValidationError( - this.fyo.t`Payment amount cannot exceed ${this.fyo.format( - this.initialAmount, - 'Currency' - )}.` + this.fyo.t`Payment amount cannot + exceed ${this.fyo.format(amount, 'Currency')}.` ); - } else if (moneyValue.isZero()) { + } else if ((value as Money).isZero()) { throw new ValidationError( - this.fyo.t`Payment amount cannot be ${this.fyo.format( - moneyValue, - 'Currency' - )}.` + this.fyo.t`Payment amount cannot + be ${this.fyo.format(value, 'Currency')}.` ); } },