From 52bf777d8dc52a81be6f81d158e7f930b70f9150 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 21 Feb 2023 16:10:06 +0530 Subject: [PATCH] fix: update display order, fix formulas --- models/baseModels/InvoiceItem/InvoiceItem.ts | 45 +++++++++++++------- models/inventory/StockMovementItem.ts | 44 ++++++++++++------- models/inventory/StockTransferItem.ts | 44 ++++++++++++------- schemas/app/InvoiceItem.json | 9 ++-- schemas/app/inventory/StockMovement.json | 1 + schemas/app/inventory/StockMovementItem.json | 9 ++-- schemas/app/inventory/StockTransferItem.json | 9 ++-- 7 files changed, 104 insertions(+), 57 deletions(-) diff --git a/models/baseModels/InvoiceItem/InvoiceItem.ts b/models/baseModels/InvoiceItem/InvoiceItem.ts index e38e1350..2e941038 100644 --- a/models/baseModels/InvoiceItem/InvoiceItem.ts +++ b/models/baseModels/InvoiceItem/InvoiceItem.ts @@ -157,26 +157,31 @@ export abstract class InvoiceItem extends Doc { dependsOn: ['item'], }, transferUnit: { - formula: async () => - (await this.fyo.getValue( + formula: async (fieldname) => { + if (fieldname === 'quantity' || fieldname === 'unit') { + return this.unit; + } + + return (await this.fyo.getValue( 'Item', this.item as string, 'unit' - )) as string, - dependsOn: ['item'], + )) as string; + }, + dependsOn: ['item', 'unit'], }, transferQuantity: { - formula: async () => { - if (this.unit === this.transferUnit) { + formula: async (fieldname) => { + if (fieldname === 'quantity' || this.unit === this.transferUnit) { return this.quantity; } return this.transferQuantity; }, - dependsOn: ['item'], + dependsOn: ['item', 'quantity'], }, quantity: { - formula: async () => { + formula: async (fieldname) => { if (!this.item) { return this.quantity as number; } @@ -186,17 +191,24 @@ export abstract class InvoiceItem extends Doc { this.item as string ); const unitDoc = itemDoc.getLink('uom'); - if (unitDoc?.isWhole) { - return Math.round( - this.transferQuantity! * this.unitConversionFactor! - ); + + let quantity: number = this.quantity ?? 1; + if (fieldname === 'transferQuantity') { + quantity = this.transferQuantity! * this.unitConversionFactor!; } - return safeParseFloat( - this.transferQuantity! * this.unitConversionFactor! - ); + if (unitDoc?.isWhole) { + return Math.round(quantity); + } + + return safeParseFloat(quantity); }, - dependsOn: ['quantity', 'transferQuantity', 'unitConversionFactor'], + dependsOn: [ + 'quantity', + 'transferQuantity', + 'transferUnit', + 'unitConversionFactor', + ], }, unitConversionFactor: { formula: async () => { @@ -420,6 +432,7 @@ export abstract class InvoiceItem extends Doc { !(this.enableDiscounting && !this.setItemDiscountAmount), transferUnit: () => !this.enableInventory, transferQuantity: () => !this.enableInventory, + unitConversionFactor: () => !this.enableInventory, }; static filters: FiltersMap = { diff --git a/models/inventory/StockMovementItem.ts b/models/inventory/StockMovementItem.ts index 35842b77..107fa509 100644 --- a/models/inventory/StockMovementItem.ts +++ b/models/inventory/StockMovementItem.ts @@ -108,26 +108,31 @@ export class StockMovementItem extends Doc { dependsOn: ['item'], }, transferUnit: { - formula: async () => - (await this.fyo.getValue( + formula: async (fieldname) => { + if (fieldname === 'quantity' || fieldname === 'unit') { + return this.unit; + } + + return (await this.fyo.getValue( 'Item', this.item as string, 'unit' - )) as string, - dependsOn: ['item'], + )) as string; + }, + dependsOn: ['item', 'unit'], }, transferQuantity: { - formula: async () => { - if (this.unit === this.transferUnit) { + formula: async (fieldname) => { + if (fieldname === 'quantity' || this.unit === this.transferUnit) { return this.quantity; } return this.transferQuantity; }, - dependsOn: ['item'], + dependsOn: ['item', 'quantity'], }, quantity: { - formula: async () => { + formula: async (fieldname) => { if (!this.item) { return this.quantity as number; } @@ -137,17 +142,24 @@ export class StockMovementItem extends Doc { this.item as string ); const unitDoc = itemDoc.getLink('uom'); - if (unitDoc?.isWhole) { - return Math.round( - this.transferQuantity! * this.unitConversionFactor! - ); + + let quantity: number = this.quantity ?? 1; + if (fieldname === 'transferQuantity') { + quantity = this.transferQuantity! * this.unitConversionFactor!; } - return safeParseFloat( - this.transferQuantity! * this.unitConversionFactor! - ); + if (unitDoc?.isWhole) { + return Math.round(quantity); + } + + return safeParseFloat(quantity); }, - dependsOn: ['quantity', 'transferQuantity', 'unitConversionFactor'], + dependsOn: [ + 'quantity', + 'transferQuantity', + 'transferUnit', + 'unitConversionFactor', + ], }, unitConversionFactor: { formula: async () => { diff --git a/models/inventory/StockTransferItem.ts b/models/inventory/StockTransferItem.ts index cb58e4f2..86883161 100644 --- a/models/inventory/StockTransferItem.ts +++ b/models/inventory/StockTransferItem.ts @@ -42,26 +42,31 @@ export class StockTransferItem extends Doc { dependsOn: ['item'], }, transferUnit: { - formula: async () => - (await this.fyo.getValue( + formula: async (fieldname) => { + if (fieldname === 'quantity' || fieldname === 'unit') { + return this.unit; + } + + return (await this.fyo.getValue( 'Item', this.item as string, 'unit' - )) as string, - dependsOn: ['item'], + )) as string; + }, + dependsOn: ['item', 'unit'], }, transferQuantity: { - formula: async () => { - if (this.unit === this.transferUnit) { + formula: async (fieldname) => { + if (fieldname === 'quantity' || this.unit === this.transferUnit) { return this.quantity; } return this.transferQuantity; }, - dependsOn: ['item'], + dependsOn: ['item', 'quantity'], }, quantity: { - formula: async () => { + formula: async (fieldname) => { if (!this.item) { return this.quantity as number; } @@ -71,17 +76,24 @@ export class StockTransferItem extends Doc { this.item as string ); const unitDoc = itemDoc.getLink('uom'); - if (unitDoc?.isWhole) { - return Math.round( - this.transferQuantity! * this.unitConversionFactor! - ); + + let quantity: number = this.quantity ?? 1; + if (fieldname === 'transferQuantity') { + quantity = this.transferQuantity! * this.unitConversionFactor!; } - return safeParseFloat( - this.transferQuantity! * this.unitConversionFactor! - ); + if (unitDoc?.isWhole) { + return Math.round(quantity); + } + + return safeParseFloat(quantity); }, - dependsOn: ['quantity', 'transferQuantity', 'unitConversionFactor'], + dependsOn: [ + 'quantity', + 'transferQuantity', + 'transferUnit', + 'unitConversionFactor', + ], }, unitConversionFactor: { formula: async () => { diff --git a/schemas/app/InvoiceItem.json b/schemas/app/InvoiceItem.json index 0d75772b..436d7170 100644 --- a/schemas/app/InvoiceItem.json +++ b/schemas/app/InvoiceItem.json @@ -28,6 +28,7 @@ "label": "Transfer Unit", "fieldtype": "Link", "target": "UOM", + "default": "Unit", "placeholder": "Unit" }, { @@ -48,7 +49,7 @@ }, { "fieldname": "quantity", - "label": "Qty. in Stock Unit", + "label": "Quantity", "fieldtype": "Float", "required": true, "default": 1 @@ -134,11 +135,13 @@ "hsnCode", "tax", "rate", - "transferUnit", + "transferQuantity", - "unit", + "transferUnit", "quantity", + "unit", "unitConversionFactor", + "amount", "setItemDiscountAmount", "itemDiscountAmount", diff --git a/schemas/app/inventory/StockMovement.json b/schemas/app/inventory/StockMovement.json index 9c6ed7cc..052f2fb4 100644 --- a/schemas/app/inventory/StockMovement.json +++ b/schemas/app/inventory/StockMovement.json @@ -62,6 +62,7 @@ "fieldtype": "Table", "target": "StockMovementItem", "required": true, + "edit": true, "section": "Items" }, { diff --git a/schemas/app/inventory/StockMovementItem.json b/schemas/app/inventory/StockMovementItem.json index ed2ca679..22a43cff 100644 --- a/schemas/app/inventory/StockMovementItem.json +++ b/schemas/app/inventory/StockMovementItem.json @@ -31,6 +31,7 @@ "label": "Transfer Unit", "fieldtype": "Link", "target": "UOM", + "default": "Unit", "placeholder": "Unit" }, { @@ -51,7 +52,7 @@ }, { "fieldname": "quantity", - "label": "Qty. in Stock Unit", + "label": "Quantity", "fieldtype": "Float", "required": true, "default": 1 @@ -82,11 +83,13 @@ "item", "fromLocation", "toLocation", - "transferUnit", + "transferQuantity", - "unit", + "transferUnit", "quantity", + "unit", "unitConversionFactor", + "rate", "amount" ] diff --git a/schemas/app/inventory/StockTransferItem.json b/schemas/app/inventory/StockTransferItem.json index 1ef8548e..96314ab3 100644 --- a/schemas/app/inventory/StockTransferItem.json +++ b/schemas/app/inventory/StockTransferItem.json @@ -22,6 +22,7 @@ "label": "Transfer Unit", "fieldtype": "Link", "target": "UOM", + "default": "Unit", "placeholder": "Unit" }, { @@ -42,7 +43,7 @@ }, { "fieldname": "quantity", - "label": "Qty. in Stock Unit", + "label": "Quantity", "fieldtype": "Float", "required": true, "default": 1 @@ -82,11 +83,13 @@ "tableFields": ["item", "location", "quantity", "rate", "amount"], "quickEditFields": [ "item", - "transferUnit", + "transferQuantity", - "unit", + "transferUnit", "quantity", + "unit", "unitConversionFactor", + "description", "hsnCode", "location",