Skip to content

Commit

Permalink
Merge pull request #392 from amansinghbais/#390
Browse files Browse the repository at this point in the history
Improved: making receipt shipment items in sync instead of using async (#390)
  • Loading branch information
ravilodhi authored Oct 11, 2024
2 parents e01ffbe + c0d3c38 commit 4deb9dc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 43 deletions.
94 changes: 56 additions & 38 deletions src/store/modules/shipment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const actions: ActionTree<ShipmentState, RootState> = {

const item = state.current.items.find((item: any) => {
const itemVal = barcodeIdentifier ? getProductIdentificationValue(barcodeIdentifier, getProduct(item.productId)) : item.internalName;
return itemVal === payload;
return itemVal === payload && item.quantityReceived === 0;
});

if (item) {
Expand All @@ -75,6 +75,7 @@ const actions: ActionTree<ShipmentState, RootState> = {
const locationSeqId = facilityLocations[0].locationSeqId
resp.data.items.map((item: any) => {
item.locationSeqId = locationSeqId;
item.quantityReceived = item.quantityAccepted ? Number(item.quantityAccepted) : 0
});
} else {
showToast(translate("Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure."))
Expand All @@ -101,48 +102,65 @@ const actions: ActionTree<ShipmentState, RootState> = {
return Promise.reject(new Error(err))
}
},
receiveShipmentItem ({ commit }, payload) {
return Promise.all(payload.items.map(async (item: any) => {
if(!item.locationSeqId) {
return Promise.reject("Missing locationSeqId on item")
}
async receiveShipmentItem ({ commit }, payload) {

Check warning on line 105 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'commit' is defined but never used

Check warning on line 105 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'commit' is defined but never used

Check warning on line 105 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'commit' is defined but never used
let areAllSuccess = true;

for (const item of payload.items) {
if(item.quantityReceived === 0) {
if (!item.locationSeqId) {
console.error("Missing locationSeqId on item");
areAllSuccess = false;
continue;
}

const params = {
shipmentId: payload.shipmentId,
facilityId: this.state.user.currentFacility.facilityId,
shipmentItemSeqId: item.itemSeqId,
productId: item.productId,
quantityAccepted: item.quantityAccepted,
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
unitCost: 0.00,
locationSeqId: item.locationSeqId
}

const params = {
shipmentId: payload.shipmentId,
facilityId: this.state.user.currentFacility.facilityId,
shipmentItemSeqId: item.itemSeqId,
productId: item.productId,
quantityAccepted: item.quantityAccepted,
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
unitCost: 0.00,
locationSeqId: item.locationSeqId
try {
const resp = await ShipmentService.receiveShipmentItem(params)
if(hasError(resp)){
throw resp.data;
}
} catch(error: any) {
areAllSuccess = false
}
}
const resp = await ShipmentService.receiveShipmentItem(params)
if(resp.status === 200 && !hasError(resp)){
return Promise.resolve(resp);
} else {
return Promise.reject(resp);
}
}))
}

return areAllSuccess;
},
async receiveShipment ({ dispatch }, payload) {
emitter.emit("presentLoader");
return await dispatch("receiveShipmentItem", payload).then(async () => {
const resp = await ShipmentService.receiveShipment({
"shipmentId": payload.shipmentId,
"statusId": "PURCH_SHIP_RECEIVED"
})
if (resp.status == 200 && !hasError(resp)) {
showToast(translate("Shipment received successfully", { shipmentId: payload.shipmentId }))
emitter.emit("presentLoader", {message: 'Receiving in-progress.', backdropDismiss: false});
const areAllSuccess = await dispatch("receiveShipmentItem", payload);
if(areAllSuccess) {
try {
const resp = await ShipmentService.receiveShipment({
"shipmentId": payload.shipmentId,
"statusId": "PURCH_SHIP_RECEIVED"
})

if (resp.status == 200 && !hasError(resp)) {
showToast(translate("Shipment received successfully", { shipmentId: payload.shipmentId }))
emitter.emit("dismissLoader");
return true;
} else {
throw resp.data;
}
} catch(error: any) {
console.error(error);
}
emitter.emit("dismissLoader");
return resp;
}).catch(err => {
emitter.emit("dismissLoader");
console.error(err)
return err;
});
}
emitter.emit("dismissLoader");
return false;
},
async addShipmentItem ({ state, commit, dispatch }, payload) {
const item = payload.shipmentId ? { ...(payload.item) } : { ...payload }
Expand Down
11 changes: 6 additions & 5 deletions src/views/ShipmentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
</div>

<div class="location">
<LocationPopover v-if="!isShipmentReceived()" :item="item" type="shipment" :facilityId="currentFacility.facilityId" />
<LocationPopover v-if="!isShipmentReceived() && item.quantityReceived === 0" :item="item" type="shipment" :facilityId="currentFacility.facilityId" />
<ion-chip :disabled="true" outline v-else>
<ion-icon :icon="locationOutline"/>
<ion-label>{{ item.locationSeqId }}</ion-label>
</ion-chip>
</div>

<div class="product-count">
<ion-item v-if="!isShipmentReceived()">
<ion-item v-if="!isShipmentReceived() && item.quantityReceived === 0">
<ion-input :label="translate('Qty')" :disabled="isForceScanEnabled" label-placement="floating" type="number" min="0" v-model="item.quantityAccepted" />
</ion-item>
<div v-else>
Expand All @@ -66,7 +66,7 @@
</div>
</div>

<ion-item lines="none" class="border-top" v-if="item.quantityOrdered > 0 && !isShipmentReceived()">
<ion-item lines="none" class="border-top" v-if="item.quantityOrdered > 0 && !isShipmentReceived() && item.quantityReceived === 0">
<ion-button @click="receiveAll(item)" :disabled="isForceScanEnabled" slot="start" fill="outline">
{{ translate("Receive All") }}
</ion-button>
Expand Down Expand Up @@ -225,11 +225,12 @@ export default defineComponent({
async receiveShipment() {
const eligibleItems = this.current.items.filter((item: any) => item.quantityAccepted > 0)
const shipmentId = this.current.shipment ? this.current.shipment.shipmentId : this.current.shipmentId
const resp = await this.store.dispatch('shipment/receiveShipment', { items: eligibleItems, shipmentId })
if (resp.status === 200 && !hasError(resp)) {
const isShipmentReceived = await this.store.dispatch('shipment/receiveShipment', { items: eligibleItems, shipmentId })
if(isShipmentReceived) {
this.router.push('/shipments');
} else {
showToast(translate("Failed to receive shipment"))
this.store.dispatch('shipment/setCurrent', { shipmentId: this.$route.params.id })
}
},
isEligibleForReceivingShipment() {
Expand Down

0 comments on commit 4deb9dc

Please sign in to comment.