feat: validate Base URL and token before syncing data from ERPNext

This commit is contained in:
AbleKSaju
2025-05-30 16:38:35 +05:30
parent dcf51593d5
commit ac1308938a
3 changed files with 26 additions and 16 deletions
+20 -8
View File
@@ -74,6 +74,7 @@ import {
registerInstanceToERPNext,
updateERPNSyncSettings,
} from './utils/erpnextSync';
import { ERPNextSyncSettings } from 'models/baseModels/ERPNextSyncSettings/ERPNextSyncSettings';
enum Screen {
Desk = 'Desk',
@@ -229,14 +230,25 @@ export default defineComponent({
await initializeInstance(filePath, false, countryCode, fyo);
await updatePrintTemplates(fyo);
try {
await registerInstanceToERPNext(fyo);
await updateERPNSyncSettings(fyo);
await ipc.initScheduler(
`${fyo.singles.ERPNextSyncSettings?.dataSyncInterval as string}m`
);
} catch (error) {
showToast({ message: error as string, type: 'error' });
const syncSettingsDoc = (await fyo.doc.getDoc(
ModelNameEnum.ERPNextSyncSettings
)) as ERPNextSyncSettings;
const baseURL = syncSettingsDoc.baseURL;
const token = syncSettingsDoc.authToken;
const enableERPNextSync =
fyo.singles.AccountingSettings?.enableERPNextSync;
if (enableERPNextSync && baseURL && token) {
try {
await registerInstanceToERPNext(fyo);
await updateERPNSyncSettings(fyo);
await ipc.initScheduler(
`${fyo.singles.ERPNextSyncSettings?.dataSyncInterval as string}m`
);
} catch (error) {
showToast({ message: error as string, type: 'error' });
}
}
await this.setDesk(filePath);
+5 -6
View File
@@ -578,11 +578,10 @@ export default defineComponent({
if (item.hasBatch) {
const isTrackItem =
this.fyo.singles.POSSettings?.itemVisibility === 'Inventory Items';
this.fyo.singles.POSSettings?.itemVisibility == 'Inventory Items';
for (const invItem of existingItems) {
const itemQty = invItem.quantity ?? 0;
const batch = invItem.batch;
if (!isTrackItem) {
invItem.quantity = quantity
@@ -600,8 +599,6 @@ export default defineComponent({
: (invItem.quantity as number) + 1;
invItem.rate = item.rate as Money;
}
}
await this.applyPricingRule();
await this.sinvDoc.runFormulas();
await validateQty(
@@ -609,6 +606,7 @@ export default defineComponent({
item as Item,
existingItems as InvoiceItem[]
);
return;
}
@@ -619,12 +617,14 @@ export default defineComponent({
item as Item,
existingItems as InvoiceItem[]
);
return;
}
await this.sinvDoc.append('items', {
rate: item.rate as Money,
item: item.name,
quantity: quantity ?? 1,
quantity: quantity ? quantity : 1,
hsnCode: itemsHsncode,
});
return;
@@ -748,7 +748,6 @@ export default defineComponent({
await this.paymentDoc.setMultiple({
paymentAccount: this.defaultPOSCashAccount,
amount: this.paidAmount.float,
clearanceDate: this.transferClearanceDate,
});
}
+1 -2
View File
@@ -156,8 +156,7 @@ export default defineComponent({
schemas(): Schema[] {
const enableInventory =
!!this.fyo.singles.AccountingSettings?.enableInventory;
const enablePOS =
!!this.fyo.singles.AccountingSettings?.enablePointOfSale;
const enablePOS = !!this.fyo.singles.InventorySettings?.enablePointOfSale;
const enableERPNextSync =
!!this.fyo.singles.AccountingSettings?.enableERPNextSync;