From ac77748a5fd8c984c01e133bb6827a8b4296a0a2 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 26 Sep 2022 18:14:59 +0530 Subject: [PATCH] fix: prevent Account Cash not found --- models/baseModels/Payment/Payment.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index 262bba45..7abffeb3 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -322,17 +322,31 @@ export class Payment extends Transactional { formulas: FormulaMap = { account: { formula: async () => { - if (this.paymentMethod === 'Cash' && this.paymentType === 'Pay') { + const hasCash = await this.fyo.db.exists(ModelNameEnum.Account, 'Cash'); + if ( + this.paymentMethod === 'Cash' && + this.paymentType === 'Pay' && + hasCash + ) { return 'Cash'; } + + return null; }, dependsOn: ['paymentMethod', 'paymentType'], }, paymentAccount: { formula: async () => { - if (this.paymentMethod === 'Cash' && this.paymentType === 'Receive') { + const hasCash = await this.fyo.db.exists(ModelNameEnum.Account, 'Cash'); + if ( + this.paymentMethod === 'Cash' && + this.paymentType === 'Receive' && + hasCash + ) { return 'Cash'; } + + return null; }, dependsOn: ['paymentMethod', 'paymentType'], }, @@ -353,7 +367,7 @@ export class Payment extends Transactional { const outstanding = partyDoc.outstandingAmount as Money; if (outstanding?.isZero() ?? true) { - return ''; + return this.paymentType; } if (outstanding?.isPositive()) {