Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: making receipt shipment items in sync instead of using async (#390) #392

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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 @@
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 / 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 @@ -121,7 +121,7 @@
import Scanner from "@/components/Scanner.vue";
import LocationPopover from '@/components/LocationPopover.vue'
import ImageModal from '@/components/ImageModal.vue';
import { hasError, showToast } from '@/utils'

Check warning on line 124 in src/views/ShipmentDetails.vue

View workflow job for this annotation

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

'hasError' is defined but never used

Check warning on line 124 in src/views/ShipmentDetails.vue

View workflow job for this annotation

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

'hasError' is defined but never used
import { Actions, hasPermission } from '@/authorization'

export default defineComponent({
Expand Down Expand Up @@ -225,11 +225,12 @@
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
Loading