From 622a4cccd3c9f6dfae4b8e47a053c6a1bcabb8f1 Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Fri, 27 Jan 2023 16:06:04 +0530 Subject: [PATCH] fix: hasBatchNumber checkbox validation --- backend/database/bespoke.ts | 2 +- models/baseModels/Item/Item.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index aa577a8d..842a137e 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -145,7 +145,7 @@ export class BespokeQueries { const value = (await query) as Record[]; - if (!value) return false; + if (!value || value.length == 0) return false; return true; } diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index 49e252c5..7f50e5ac 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -27,17 +27,19 @@ export class Item extends Doc { * allowing users to change the value of Has Batch No of the items which already did transactions will result in incorect SLEs */ - const ifItemHasBatchNumber = await Boolean( - this.fyo.db.get('Item', this.name! || '', 'hasBatchNumber') + const ifItemHasBatchNumber = await this.fyo.db.get( + 'Item', + this.name!, + 'hasBatchNumber' ); - if (this.hasBatchNumber == ifItemHasBatchNumber) { + if (this.hasBatchNumber == ifItemHasBatchNumber.hasBatchNumber) { return; } const isItemExistsInSLE = await this.fyo.db.itemHasTransactions(this.name!); - if (ifItemHasBatchNumber && isItemExistsInSLE) { + if (isItemExistsInSLE) { throw new ValidationError( this.fyo.t`Cannot change value of Has Batch No as ${this .name!} already has transactions against it. `