From b7aca5ac1ace13a3d02a542fd8215df914bea76a Mon Sep 17 00:00:00 2001 From: Ragnar Laud Date: Sat, 20 Jan 2024 15:41:29 +0200 Subject: [PATCH 1/3] Create migration Alter quantity column to a decimal(17, 7) --- ...20132327_convert_items_entries_quantity_to_decimal.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/server/src/database/migrations/20240120132327_convert_items_entries_quantity_to_decimal.js diff --git a/packages/server/src/database/migrations/20240120132327_convert_items_entries_quantity_to_decimal.js b/packages/server/src/database/migrations/20240120132327_convert_items_entries_quantity_to_decimal.js new file mode 100644 index 000000000..6f77a8d02 --- /dev/null +++ b/packages/server/src/database/migrations/20240120132327_convert_items_entries_quantity_to_decimal.js @@ -0,0 +1,9 @@ +exports.up = function(knex) { + return knex.schema.alterTable('items_entries', (table) => { + table.decimal('quantity', 17, 7).alter(); + }); +}; + +exports.down = function(knex) { + return knex.table('items_entries', (table) => { }); +}; From 49691735ef313c2081b16ec44c705f5c4958920f Mon Sep 17 00:00:00 2001 From: Ragnar Laud Date: Sat, 20 Jan 2024 15:42:13 +0200 Subject: [PATCH 2/3] Update quantity validators Validate quantity as decimal --- .../src/api/controllers/Inventory/InventoryAdjustments.ts | 4 ++-- packages/server/src/api/controllers/Purchases/Bills.ts | 2 +- packages/server/src/api/controllers/Purchases/VendorCredit.ts | 4 ++-- packages/server/src/api/controllers/Sales/CreditNotes.ts | 2 +- packages/server/src/api/controllers/Sales/SalesEstimates.ts | 2 +- packages/server/src/api/controllers/Sales/SalesReceipts.ts | 2 +- .../src/api/controllers/Warehouses/WarehouseTransfers.ts | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts b/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts index 40b1744ff..f633da72e 100644 --- a/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts +++ b/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts @@ -113,8 +113,8 @@ export default class InventoryAdjustmentsController extends BaseController { check('quantity') .if(check('type').exists().isIn(['increment', 'decrement'])) .exists() - .isInt() - .toInt(), + .isDecimal() + .toFloat(), check('cost') .if(check('type').exists().isIn(['increment'])) .exists() diff --git a/packages/server/src/api/controllers/Purchases/Bills.ts b/packages/server/src/api/controllers/Purchases/Bills.ts index 2cd9e62de..61fc5cf70 100644 --- a/packages/server/src/api/controllers/Purchases/Bills.ts +++ b/packages/server/src/api/controllers/Purchases/Bills.ts @@ -122,7 +122,7 @@ export default class BillsController extends BaseController { check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), check('entries.*.rate').exists().isNumeric().toFloat(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.discount') .optional({ nullable: true }) .isNumeric() diff --git a/packages/server/src/api/controllers/Purchases/VendorCredit.ts b/packages/server/src/api/controllers/Purchases/VendorCredit.ts index 3d2832308..73636ca0a 100644 --- a/packages/server/src/api/controllers/Purchases/VendorCredit.ts +++ b/packages/server/src/api/controllers/Purchases/VendorCredit.ts @@ -173,7 +173,7 @@ export default class VendorCreditController extends BaseController { check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), check('entries.*.rate').exists().isNumeric().toFloat(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.discount') .optional({ nullable: true }) .isNumeric() @@ -215,7 +215,7 @@ export default class VendorCreditController extends BaseController { check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), check('entries.*.rate').exists().isNumeric().toFloat(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.discount') .optional({ nullable: true }) .isNumeric() diff --git a/packages/server/src/api/controllers/Sales/CreditNotes.ts b/packages/server/src/api/controllers/Sales/CreditNotes.ts index 77b506c7d..29bcae2fb 100644 --- a/packages/server/src/api/controllers/Sales/CreditNotes.ts +++ b/packages/server/src/api/controllers/Sales/CreditNotes.ts @@ -222,7 +222,7 @@ export default class PaymentReceivesController extends BaseController { check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), check('entries.*.rate').exists().isNumeric().toFloat(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.discount') .optional({ nullable: true }) .isNumeric() diff --git a/packages/server/src/api/controllers/Sales/SalesEstimates.ts b/packages/server/src/api/controllers/Sales/SalesEstimates.ts index b34c1ccf2..37da1793c 100644 --- a/packages/server/src/api/controllers/Sales/SalesEstimates.ts +++ b/packages/server/src/api/controllers/Sales/SalesEstimates.ts @@ -166,7 +166,7 @@ export default class SalesEstimatesController extends BaseController { check('entries').exists().isArray({ min: 1 }), check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.rate').exists().isNumeric().toFloat(), check('entries.*.description') .optional({ nullable: true }) diff --git a/packages/server/src/api/controllers/Sales/SalesReceipts.ts b/packages/server/src/api/controllers/Sales/SalesReceipts.ts index 6151561f8..fccbfc8f3 100644 --- a/packages/server/src/api/controllers/Sales/SalesReceipts.ts +++ b/packages/server/src/api/controllers/Sales/SalesReceipts.ts @@ -139,7 +139,7 @@ export default class SalesReceiptsController extends BaseController { check('entries.*.id').optional({ nullable: true }).isNumeric().toInt(), check('entries.*.index').exists().isNumeric().toInt(), check('entries.*.item_id').exists().isNumeric().toInt(), - check('entries.*.quantity').exists().isNumeric().toInt(), + check('entries.*.quantity').exists().isNumeric().toFloat(), check('entries.*.rate').exists().isNumeric().toFloat(), check('entries.*.discount') .optional({ nullable: true }) diff --git a/packages/server/src/api/controllers/Warehouses/WarehouseTransfers.ts b/packages/server/src/api/controllers/Warehouses/WarehouseTransfers.ts index de7385786..b793f64bb 100644 --- a/packages/server/src/api/controllers/Warehouses/WarehouseTransfers.ts +++ b/packages/server/src/api/controllers/Warehouses/WarehouseTransfers.ts @@ -39,7 +39,7 @@ export class WarehousesTransfers extends BaseController { check('entries.*.index').exists(), check('entries.*.item_id').exists(), check('entries.*.description').optional(), - check('entries.*.quantity').exists().isInt().toInt(), + check('entries.*.quantity').exists().isDecimal().toFloat(), check('entries.*.cost').optional().isDecimal().toFloat(), ], this.validationResult, @@ -66,7 +66,7 @@ export class WarehousesTransfers extends BaseController { check('entries.*.index').exists(), check('entries.*.item_id').exists().isInt().toInt(), check('entries.*.description').optional(), - check('entries.*.quantity').exists().isInt({ min: 1 }).toInt(), + check('entries.*.quantity').exists().isDecimal().toFloat(), check('entries.*.cost').optional().isDecimal().toFloat(), ], this.validationResult, From 790b3a02c13e0fd87dbca2e4b472fa439f5ca95b Mon Sep 17 00:00:00 2001 From: Ragnar Laud Date: Sat, 20 Jan 2024 15:42:40 +0200 Subject: [PATCH 3/3] Add TODO Found a cost validator that is validated as an integer Trigger actions --- .../server/src/api/controllers/Inventory/InventoryAdjustments.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts b/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts index f633da72e..8da38f5be 100644 --- a/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts +++ b/packages/server/src/api/controllers/Inventory/InventoryAdjustments.ts @@ -115,6 +115,7 @@ export default class InventoryAdjustmentsController extends BaseController { .exists() .isDecimal() .toFloat(), + // TODO: Is the cost supposed to be an integer here if it's a float everywhere else? check('cost') .if(check('type').exists().isIn(['increment'])) .exists()