Skip to content

Commit

Permalink
feat: sync stockMovement
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayitzme committed Dec 5, 2024
1 parent b28aa8e commit 9d3f0fd
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/utils/erpnextSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DocValueMap } from 'fyo/core/types';
import { Doc } from 'fyo/model/doc';
import { ERPNextSyncQueue } from 'models/baseModels/ERPNextSyncQueue/ERPNextSyncQueue';
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
import { StockMovementItem } from 'models/inventory/StockMovementItem';

export async function updateERPNSyncSettings(fyo: Fyo) {
const syncSettingsDoc = (await fyo.doc.getDoc(
Expand Down Expand Up @@ -193,23 +194,41 @@ async function performPreSync(fyo: Fyo, doc: DocValueMap) {
}
return;

case ModelNameEnum.Party:
case 'Customer':
case 'Supplier':
const isAddressExists = await fyo.db.exists(
ModelNameEnum.Address,
doc.addressName as string
doc.address as string
);

if (!isAddressExists) {
await addToFetchFromERPNextQueue(fyo, {
referenceType: ModelNameEnum.Address,
documentName: doc.addressName,
documentName: doc.address,
});
}

return;

case ModelNameEnum.SalesInvoice:
return await preSyncSalesInvoice(fyo, doc as SalesInvoice);

case ModelNameEnum.StockMovement:
if (!doc || !doc.items) {
return;
}

for (const item of doc.items as StockMovementItem[]) {
const isItemExists = await fyo.db.exists(ModelNameEnum.Item, item.item);

if (!isItemExists) {
await addToFetchFromERPNextQueue(fyo, {
referenceType: ModelNameEnum.Item,
documentName: item.item,
});
}
}
return;
default:
return;
}
Expand Down Expand Up @@ -364,7 +383,9 @@ export async function syncDocumentsToERPNext(fyo: Fyo) {
await logDoc.delete();
}
}
} catch (error) {}
} catch (error) {
return error;
}
}

async function syncFetchFromERPNextQueue(fyo: Fyo) {
Expand Down Expand Up @@ -551,6 +572,12 @@ export interface ERPNSyncDocsResponse {
failed_log?: DocValueMap[];
};
}
export interface FetchFromBooksResponse {
message: {
success: boolean;
data?: DocValueMap[];
};
}

export interface ERPNextSyncSettingsAPIResponse {
message: {
Expand Down

0 comments on commit 9d3f0fd

Please sign in to comment.