fix(lot transfer): changes to make it so the reprint and return do not happen instantly

This commit is contained in:
2025-12-02 15:24:10 -06:00
parent a3dba6cc9d
commit ac27a286c0
2 changed files with 107 additions and 90 deletions

View File

@@ -3,6 +3,7 @@ import { eq } from "drizzle-orm";
import { success } from "zod/v4";
import { db } from "../../../../../database/dbclient.js";
import { printerData } from "../../../../../database/schema/printers.js";
import { delay } from "../../../../globalUtils/delay.js";
import { runProdApi } from "../../../../globalUtils/runProdApi.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";
@@ -158,7 +159,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
};
}
let timeoutTrans: number = data.type === "lot" ? 30 : 10;
let timeoutTrans: number = data.type === "lot" ? 5 : 5;
// get the barcode, and layoutID from the running number
const { data: label, error: labelError } = (await tryCatch(
query(
@@ -278,13 +279,10 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
};
//console.log(matReturnData);
const { data: matReturn, error: matReturError } = (await tryCatch(
runProdApi({
endpoint:
"/public/v1.0/IssueMaterial/ReturnPartiallyConsumedManualMaterial",
data: [matReturnData],
}),
)) as any;
// set a delay for when we try to return the label
const matReturn = await returnMaterial(matReturnData);
if (!matReturn.success) {
createLog(
@@ -305,12 +303,12 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
barcode: label?.data[0].Barcode,
};
const delay =
const delayTimer =
data.type === "lot"
? timeoutTrans * 1000
: target.getTime() - now.getTime();
const transfer = await transferMaterial(delay, data, consumeLot, newQty);
const transfer = await transferMaterial(delayTimer, data, consumeLot, newQty);
if (!transfer.success) {
return {
@@ -340,6 +338,22 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
}
};
const returnMaterial = async (matReturnData: any) => {
console.log("Getting ready to Returning Materials");
await delay(5 * 1000);
console.log("doing the return");
const { data: matReturn, error: matReturError } = (await tryCatch(
runProdApi({
endpoint:
"/public/v1.0/IssueMaterial/ReturnPartiallyConsumedManualMaterial",
data: [matReturnData],
}),
)) as any;
if (matReturError) return matReturError;
return matReturn;
};
const transferMaterial = async (
delay: number,
data: any,
@@ -347,12 +361,13 @@ const transferMaterial = async (
newQty: any,
) => {
//console.log(data);
console.log("Transferring the material");
if (pendingJobs.has(data.runningNumber)) {
createLog(
"error",
"materials",
"ocp",
`${data.runningNumber} is pending to be transfered already`,
`${data.runningNumber} is pending to be transferred already`,
);
return {
success: false,