From 6805ebcaba14c33a0960e23f5b7409cedd4ce6ca Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 1 Nov 2022 18:51:21 +0530 Subject: [PATCH] fix: allow location to be common --- backend/database/core.ts | 8 ++++++++ models/inventory/StockMovementItem.ts | 5 ++--- models/inventory/types.ts | 11 +++++------ schemas/app/inventory/Location.json | 4 +--- utils/db/types.ts | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/backend/database/core.ts b/backend/database/core.ts index f02fe269..13ce40ab 100644 --- a/backend/database/core.ts +++ b/backend/database/core.ts @@ -484,6 +484,14 @@ export default class DatabaseCore extends DatabaseBase { if (operator === '=') { builder.where(field, comparisonValue); + } else if ( + operator === 'in' && + (comparisonValue as (string | null)[]).includes(null) + ) { + const nonNulls = (comparisonValue as (string | null)[]).filter( + Boolean + ) as string[]; + builder.where(field, operator, nonNulls).orWhere(field, null); } else { builder.where(field, operator as string, comparisonValue as string); } diff --git a/models/inventory/StockMovementItem.ts b/models/inventory/StockMovementItem.ts index 7698b6cc..c5743792 100644 --- a/models/inventory/StockMovementItem.ts +++ b/models/inventory/StockMovementItem.ts @@ -13,10 +13,10 @@ import { StockMovement } from './StockMovement'; const locationFilter: FilterFunction = (doc: Doc) => { const item = doc.item; if (!doc.item) { - return {}; + return { item: null }; } - return { item } as QueryFilter; + return { item: ['in', [null, item]] } as QueryFilter; }; export class StockMovementItem extends Doc { @@ -38,7 +38,6 @@ export class StockMovementItem extends Doc { formulas: FormulaMap = { rate: { formula: async () => { - console.log('called', this.item); if (!this.item) { return this.rate; } diff --git a/models/inventory/types.ts b/models/inventory/types.ts index fee0a028..16ee2de3 100644 --- a/models/inventory/types.ts +++ b/models/inventory/types.ts @@ -1,9 +1,10 @@ import { Money } from 'pesa'; -export type MovementType = - | 'MaterialIssue' - | 'MaterialReceipt' - | 'MaterialTransfer'; +export enum MovementType { + 'MaterialIssue' = 'MaterialIssue', + 'MaterialReceipt' = 'MaterialReceipt', + 'MaterialTransfer' = 'MaterialTransfer', +} export interface SMDetails { date: Date; @@ -20,5 +21,3 @@ export interface SMTransferDetails { } export interface SMIDetails extends SMDetails, SMTransferDetails {} - - diff --git a/schemas/app/inventory/Location.json b/schemas/app/inventory/Location.json index 13536ae3..e25047be 100644 --- a/schemas/app/inventory/Location.json +++ b/schemas/app/inventory/Location.json @@ -15,9 +15,7 @@ "fieldname": "item", "label": "Item", "fieldtype": "Link", - "target": "Item", - "required": true, - "readOnly": true + "target": "Item" } ], "quickEditFields": ["item"] diff --git a/utils/db/types.ts b/utils/db/types.ts index 7c33f740..22a6fad1 100644 --- a/utils/db/types.ts +++ b/utils/db/types.ts @@ -64,7 +64,7 @@ export interface GetAllOptions { export type QueryFilter = Record< string, - boolean | string | (string | number | (string | number)[])[] + boolean | string | null | (string | number | (string | number | null)[])[] >; /**