From 47ed0f9397cfd7dccb732c3579eedb8624e47e6a Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Mon, 4 Nov 2024 12:31:29 +0530 Subject: [PATCH 1/5] chore: fixed floating promise warning when linting --- models/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/helpers.ts b/models/helpers.ts index bd6bdef88..6e1b94410 100644 --- a/models/helpers.ts +++ b/models/helpers.ts @@ -1201,7 +1201,7 @@ export async function updatePricingRule(sinvDoc: SalesInvoice) { ).length; setTimeout(() => { - (async () => { + void (async () => { if (appliedPricingRuleCount !== applicablePricingRuleNames?.length) { await sinvDoc.appendPricingRuleDetail(applicablePricingRuleNames); await sinvDoc.applyProductDiscount(); From 3c195804712258fbf0b3fc66610b97a6266d80e1 Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Mon, 4 Nov 2024 12:33:22 +0530 Subject: [PATCH 2/5] fix: patch to fix wrong field datatype of hsnCode --- backend/patches/fixItemHSNField.ts | 11 +++++++++++ backend/patches/index.ts | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 backend/patches/fixItemHSNField.ts diff --git a/backend/patches/fixItemHSNField.ts b/backend/patches/fixItemHSNField.ts new file mode 100644 index 000000000..5027b045b --- /dev/null +++ b/backend/patches/fixItemHSNField.ts @@ -0,0 +1,11 @@ +import { DatabaseManager } from '../database/manager'; + +async function execute(dm: DatabaseManager) { + const knexSchema = dm.db?.knex?.schema; + + await knexSchema?.alterTable('Item', (table) => { + table.text('hsnCode').alter(); + }); +} + +export default { execute, beforeMigrate: true }; diff --git a/backend/patches/index.ts b/backend/patches/index.ts index c9df6a2ad..78edbe842 100644 --- a/backend/patches/index.ts +++ b/backend/patches/index.ts @@ -6,6 +6,7 @@ import testPatch from './testPatch'; import updateSchemas from './updateSchemas'; import setPaymentReferenceType from './setPaymentReferenceType'; import fixLedgerDateTime from './v0_21_0/fixLedgerDateTime'; +import fixItemHSNField from './fixItemHSNField'; export default [ { name: 'testPatch', version: '0.5.0-beta.0', patch: testPatch }, @@ -40,4 +41,5 @@ export default [ version: '0.21.2', patch: fixLedgerDateTime, }, + { name: 'fixItemHSNField', version: '0.24.0', patch: fixItemHSNField }, ] as Patch[]; From 73adacc7843d64ddc81e10a0341732fb4d331a4e Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Mon, 4 Nov 2024 12:33:44 +0530 Subject: [PATCH 3/5] fix: fieldType of hsncode --- schemas/app/Item.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/app/Item.json b/schemas/app/Item.json index bca78af5e..b3abae237 100644 --- a/schemas/app/Item.json +++ b/schemas/app/Item.json @@ -113,7 +113,7 @@ { "fieldname": "hsnCode", "label": "HSN/SAC", - "fieldtype": "Int", + "fieldtype": "Data", "placeholder": "HSN/SAC Code", "section": "Inventory" }, From dca298fa75dffda459ac143d8f596f0c8fb45b3c Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Mon, 4 Nov 2024 12:49:07 +0530 Subject: [PATCH 4/5] feat: validate hsnCode --- models/baseModels/Item/Item.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/baseModels/Item/Item.ts b/models/baseModels/Item/Item.ts index 351bf5b57..fae6d8ac3 100644 --- a/models/baseModels/Item/Item.ts +++ b/models/baseModels/Item/Item.ts @@ -76,6 +76,11 @@ export class Item extends Doc { throw new ValidationError(this.fyo.t`Rate can't be negative.`); } }, + hsnCode: (value: DocValue) => { + if (value && !(value as string).match(/^\d{4,8}$/)) { + throw new ValidationError(this.fyo.t`Invalid HSN Code.`); + } + }, }; static getActions(fyo: Fyo): Action[] { From 302376d912e8fc109229d47cd58f42838f018d95 Mon Sep 17 00:00:00 2001 From: akshayitzme Date: Tue, 5 Nov 2024 09:39:04 +0530 Subject: [PATCH 5/5] chore: set hsn values as string --- dummy/items.json | 2 +- tests/items.csv | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dummy/items.json b/dummy/items.json index 09acafbb4..4bfdc09dd 100644 --- a/dummy/items.json +++ b/dummy/items.json @@ -1 +1 @@ -[{"name": "Dry-Cleaning", "description": null, "unit": "Unit", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 69, "hsnCode": 999712, "for": "Sales"}, {"name": "Electricity", "description": "Bzz Bzz", "unit": "Day", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Utility Expenses", "tax": "GST-0", "rate": 6000, "hsnCode": 271600, "for": "Purchases"}, {"name": "Marketing - Video", "description": "One single video", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Marketing Expenses", "tax": "GST-18", "rate": 15000, "hsnCode": 998371, "for": "Purchases"}, {"name": "Office Rent", "description": "Rent per day", "unit": "Day", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Office Rent", "tax": "GST-18", "rate": 50000, "hsnCode": 997212, "for": "Purchases"}, {"name": "Office Cleaning", "description": "Cleaning cost per day", "unit": "Day", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Office Maintenance Expenses", "tax": "GST-18", "rate": 7500, "hsnCode": 998533, "for": "Purchases"}, {"name": "Social Ads", "description": "Cost per click", "unit": "Unit", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Marketing Expenses", "tax": "GST-18", "rate": 50, "hsnCode": 99836, "for": "Purchases"}, {"name": "Cool Cloth", "description": "Some real \ud83c\udd92 cloth", "unit": "Meter", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 4000, "hsnCode": 59111000, "for": "Both"}, {"name": "611 Jeans - PCH", "description": "Peach coloured 611s", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 4499, "hsnCode": 62034990, "for": "Both"}, {"name": "611 Jeans - SHR", "description": "Shark skin 611s", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 6499, "hsnCode": 62034990, "for": "Both"}, {"name": "Bominga Shoes", "description": null, "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 4999, "hsnCode": 640291, "for": "Both"}, {"name": "Cryo Gloves", "description": "Keeps hands cool", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 3499, "hsnCode": 611693, "for": "Both"}, {"name": "Epaulettes - 4POR", "description": "Porcelain epaulettes", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 2499, "hsnCode": 62179090, "for": "Both"}, {"name": "Full Sleeve - BLK", "description": "Black sleeved", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 599, "hsnCode": 100820, "for": "Both"}, {"name": "Full Sleeve - COL", "description": "All color sleeved", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 499, "hsnCode": 100820, "for": "Both"}, {"name": "Jacket - RAW", "description": "Raw baby skinned jackets", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 8999, "hsnCode": 100820, "for": "Both"}, {"name": "Jade Slippers", "description": null, "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 2999, "hsnCode": 640520, "for": "Both"}] \ No newline at end of file +[{"name": "Dry-Cleaning", "description": null, "unit": "Unit", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 69, "hsnCode": "999712", "for": "Sales"}, {"name": "Electricity", "description": "Bzz Bzz", "unit": "Day", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Utility Expenses", "tax": "GST-0", "rate": 6000, "hsnCode": "271600", "for": "Purchases"}, {"name": "Marketing - Video", "description": "One single video", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Marketing Expenses", "tax": "GST-18", "rate": 15000, "hsnCode": "998371", "for": "Purchases"}, {"name": "Office Rent", "description": "Rent per day", "unit": "Day", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Office Rent", "tax": "GST-18", "rate": 50000, "hsnCode": "997212", "for": "Purchases"}, {"name": "Office Cleaning", "description": "Cleaning cost per day", "unit": "Day", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Office Maintenance Expenses", "tax": "GST-18", "rate": 7500, "hsnCode": "998533", "for": "Purchases"}, {"name": "Social Ads", "description": "Cost per click", "unit": "Unit", "itemType": "Service", "incomeAccount": "Service", "expenseAccount": "Marketing Expenses", "tax": "GST-18", "rate": 50, "hsnCode": "99836", "for": "Purchases"}, {"name": "Cool Cloth", "description": "Some real \ud83c\udd92 cloth", "unit": "Meter", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 4000, "hsnCode": "59111000", "for": "Both"}, {"name": "611 Jeans - PCH", "description": "Peach coloured 611s", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 4499, "hsnCode": "62034990", "for": "Both"}, {"name": "611 Jeans - SHR", "description": "Shark skin 611s", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 6499, "hsnCode": "62034990", "for": "Both"}, {"name": "Bominga Shoes", "description": null, "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 4999, "hsnCode": "640291", "for": "Both"}, {"name": "Cryo Gloves", "description": "Keeps hands cool", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 3499, "hsnCode": "611693", "for": "Both"}, {"name": "Epaulettes - 4POR", "description": "Porcelain epaulettes", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 2499, "hsnCode": "62179090", "for": "Both"}, {"name": "Full Sleeve - BLK", "description": "Black sleeved", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 599, "hsnCode": "100820", "for": "Both"}, {"name": "Full Sleeve - COL", "description": "All color sleeved", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 499, "hsnCode": "100820", "for": "Both"}, {"name": "Jacket - RAW", "description": "Raw baby skinned jackets", "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-12", "rate": 8999, "hsnCode": "100820", "for": "Both"}, {"name": "Jade Slippers", "description": null, "unit": "Unit", "itemType": "Product", "incomeAccount": "Sales", "expenseAccount": "Cost of Goods Sold", "tax": "GST-18", "rate": 2999, "hsnCode": "640520", "for": "Both"}] \ No newline at end of file diff --git a/tests/items.csv b/tests/items.csv index bd5ff56d3..8cb4b85ae 100644 --- a/tests/items.csv +++ b/tests/items.csv @@ -1,13 +1,13 @@ -"Item Name",Description,"Unit Type",Type,For,"Sales Acc.","Purchase Acc.",Tax,Rate,HSN/SAC,Barcode,"Track Item","Created By","Modified By",Created,Modified -Item.name,Item.description,Item.unit,Item.itemType,Item.for,Item.incomeAccount,Item.expenseAccount,Item.tax,Item.rate,Item.hsnCode,Item.barcode,Item.trackItem,Item.createdBy,Item.modifiedBy,Item.created,Item.modified -"Final Item","A final item made from raw items",Unit,Product,Both,Sales,"Stock Received But Not Billed",,500,0,,1,lin@to.co,lin@to.co,2023-01-31T06:46:00.200Z,2023-01-31T06:46:00.200Z -"Raw Two","Another Raw item used to make a final item",Unit,Product,Both,Sales,"Stock Received But Not Billed",,200,0,,1,lin@to.co,lin@to.co,2023-01-31T06:45:32.449Z,2023-01-31T06:45:32.449Z -"Raw One","A raw item used to make a final item.",Unit,Product,Both,Sales,"Stock Received But Not Billed",,100,0,,1,lin@to.co,lin@to.co,2023-01-31T06:44:58.047Z,2023-01-31T06:44:58.047Z -"Test One",,Unit,Product,Both,Sales,"Stock Received But Not Billed",GST-18,200,0,,1,lin@to.co,lin@to.co,2023-01-09T10:46:02.217Z,2023-01-09T10:46:02.217Z -Stuff,"Some stuff.",Unit,Product,Both,Sales,"Stock Received But Not Billed",GST-18,200,101192,,1,lin@to.co,lin@to.co,2023-01-09T07:14:12.208Z,2023-01-09T07:14:12.208Z -"Something Sellable",,Unit,Product,Sales,Sales,"Cost of Goods Sold",,300,0,,0,lin@to.co,lin@to.co,2022-10-11T09:15:15.724Z,2023-01-16T08:49:49.267Z -Ball,"Just a ball..",Unit,Product,Both,Sales,"Cost of Goods Sold",,30,0,,0,Administrator,Administrator,2022-02-24T04:38:09.181Z,2022-02-24T04:38:09.181Z -Bat,"Regular old bat...",Unit,Product,Both,Sales,"Cost of Goods Sold",,129,0,,0,Administrator,Administrator,2022-02-24T04:38:09.174Z,2022-02-24T04:38:09.174Z -"Holy Icon","The holiest of icons.",Unit,Product,Both,Sales,"Cost of Goods Sold",GST-3,330,0,,0,Administrator,Administrator,2022-02-11T11:32:33.342Z,2022-02-11T11:32:33.342Z -"Flower Pot","Just a flower pot.",Unit,Product,Both,Sales,"Cost of Goods Sold",GST-12,200,,,0,Administrator,Administrator,2021-12-16T07:04:08.233Z,2021-12-16T07:04:08.233Z -Flow,"Used to test the flow of operations.",Unit,Product,Both,Sales,"Cost of Goods Sold",GST-12,100,,,0,Administrator,Administrator,2021-12-16T05:42:02.081Z,2021-12-16T05:48:48.203Z \ No newline at end of file +Item Name,Description,Unit Type,Type,For,Sales Acc.,Purchase Acc.,Tax,Rate,HSN/SAC,Barcode,Track Item,Created By,Modified By,Created,Modified +Item.name,Item.description,Item.unit,Item.itemType,Item.for,Item.incomeAccount,Item.expenseAccount,Item.tax,Item.rate,Item.hsnCode,Item.barcode,Item.trackItem,Item.createdBy,Item.modifiedBy,Item.created,Item.modified +Final Item,A final item made from raw items,Unit,Product,Both,Sales,Stock Received But Not Billed,,500,,,1,lin@to.co,lin@to.co,2023-01-31T06:46:00.200Z,2023-01-31T06:46:00.200Z +Raw Two,Another Raw item used to make a final item,Unit,Product,Both,Sales,Stock Received But Not Billed,,200,,,1,lin@to.co,lin@to.co,2023-01-31T06:45:32.449Z,2023-01-31T06:45:32.449Z +Raw One,A raw item used to make a final item.,Unit,Product,Both,Sales,Stock Received But Not Billed,,100,,,1,lin@to.co,lin@to.co,2023-01-31T06:44:58.047Z,2023-01-31T06:44:58.047Z +Test One,,Unit,Product,Both,Sales,Stock Received But Not Billed,GST-18,200,,,1,lin@to.co,lin@to.co,2023-01-09T10:46:02.217Z,2023-01-09T10:46:02.217Z +Stuff,Some stuff.,Unit,Product,Both,Sales,Stock Received But Not Billed,GST-18,200,101192,,1,lin@to.co,lin@to.co,2023-01-09T07:14:12.208Z,2023-01-09T07:14:12.208Z +Something Sellable,,Unit,Product,Sales,Sales,Cost of Goods Sold,,300,,,0,lin@to.co,lin@to.co,2022-10-11T09:15:15.724Z,2023-01-16T08:49:49.267Z +Ball,Just a ball..,Unit,Product,Both,Sales,Cost of Goods Sold,,30,,,0,Administrator,Administrator,2022-02-24T04:38:09.181Z,2022-02-24T04:38:09.181Z +Bat,Regular old bat...,Unit,Product,Both,Sales,Cost of Goods Sold,,129,,,0,Administrator,Administrator,2022-02-24T04:38:09.174Z,2022-02-24T04:38:09.174Z +Holy Icon,The holiest of icons.,Unit,Product,Both,Sales,Cost of Goods Sold,GST-3,330,,,0,Administrator,Administrator,2022-02-11T11:32:33.342Z,2022-02-11T11:32:33.342Z +Flower Pot,Just a flower pot.,Unit,Product,Both,Sales,Cost of Goods Sold,GST-12,200,,,0,Administrator,Administrator,2021-12-16T07:04:08.233Z,2021-12-16T07:04:08.233Z +Flow,Used to test the flow of operations.,Unit,Product,Both,Sales,Cost of Goods Sold,GST-12,100,,,0,Administrator,Administrator,2021-12-16T05:42:02.081Z,2021-12-16T05:48:48.203Z