Skip to content

Commit

Permalink
fix: improved the handling of facilityLocations(#31a0f22)
Browse files Browse the repository at this point in the history
  • Loading branch information
disha1202 committed Feb 7, 2023
1 parent c89d258 commit 8a70310
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/BulkInventoryAdjustmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export default defineComponent({
},
async save() {
const facilityLocations = await this.store.dispatch('user/fetchFacilityLocations', [this.facilityId]);
const locationSeqId = facilityLocations[this.facilityId] && facilityLocations[this.facilityId][0] ? facilityLocations[this.facilityId][0].locationSeqId : '';
await this.stock.parsed.map((item: any) => {
if (item.isSelected) {
if(this.quantityBuffer != '')
item.quantity = this.quantityBuffer;
if(this.facilityId) {
item.facilityId = this.facilityId;
item.externalFacilityId = "";
//TODO: Need to improve the handling of locationSeqId.
item.locationSeqId = facilityLocations && facilityLocations[0] && facilityLocations[0].locationSeqId ? facilityLocations[0].locationSeqId : "";
item.locationSeqId = locationSeqId;
}
}
})
Expand Down
5 changes: 2 additions & 3 deletions src/components/MissingFacilitiesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export default defineComponent({
...mapGetters({
purchaseOrders: 'order/getPurchaseOrders',
stock: 'stock/getItemsStock',
getFacilityLocationsByFacilityId: 'user/getFacilityLocationsByFacilityId',
})
},
mounted(){
Expand All @@ -100,9 +99,9 @@ export default defineComponent({
})
this.store.dispatch('order/updatePurchaseOrders', this.purchaseOrders);
} else {
await this.store.dispatch('user/fetchFacilityLocations', Object.values(this.facilityMapping));
const facilityLocations = await this.store.dispatch('user/fetchFacilityLocations', Object.values(this.facilityMapping));
Object.keys(this.facilityMapping).map((facilityId: any) => {
const locationSeqId = this.getFacilityLocationsByFacilityId(this.facilityMapping[facilityId]).length ? this.getFacilityLocationsByFacilityId(this.facilityMapping[facilityId])[0].locationSeqId : '';
const locationSeqId = facilityLocations[this.facilityMapping[facilityId]].length ? facilityLocations[this.facilityMapping[facilityId]][0].locationSeqId : '';
this.stock.parsed.map((item: any) => {
if(item.externalFacilityId === facilityId){
item.externalFacilityId = "";
Expand Down
18 changes: 10 additions & 8 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ const actions: ActionTree<UserState, RootState> = {
updateInstanceUrl(payload)
},

async fetchFacilityLocations({ commit }, facilityId){
async fetchFacilityLocations({ commit, state }, facilityIds){
facilityIds = facilityIds.filter((facilityId: any) => !state.facilityLocationsByFacilityId[facilityId])
if(!facilityIds.length) return state.facilityLocationsByFacilityId;

let resp;
const params = {
"inputFields": {
facilityId,
facilityId: facilityIds,
"facilityId_op": 'in'
},
// Assuming we will not have more than 20 facility locations, hardcoded the viewSize value 20.
Expand All @@ -142,7 +145,7 @@ const actions: ActionTree<UserState, RootState> = {
"distinct": "Y",
"noConditionFind": "Y"
}
try{
try {
resp = await UserService.getFacilityLocations(params);
if(resp.status === 200 && !hasError(resp) && resp.data?.count > 0) {
let facilityLocations = resp.data.docs
Expand All @@ -152,18 +155,17 @@ const actions: ActionTree<UserState, RootState> = {
locationSeqId: location.locationSeqId,
locationPath: locationPath
}
locations.push(facilityLocation);
locations[location.facilityId] ? locations[location.facilityId].push(facilityLocation) : locations[location.facilityId] = [facilityLocation];
return locations;
}, []);
commit(types.USER_FACILITY_LOCATIONS_BY_FACILITY_ID, { facilityLocations, facilityId });
return facilityLocations;
}, {});
commit(types.USER_FACILITY_LOCATIONS_BY_FACILITY_ID, facilityLocations);
} else {
console.error(resp);
}
} catch(err) {
console.error(err);
return [];
}
return state.facilityLocationsByFacilityId;
},

async getFieldMappings({ commit }) {
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ const mutations: MutationTree <UserState> = {
[types.USER_DATETIME_FORMAT_UPDATED] (state, payload) {
state.preferredDateTimeFormat = payload;
},
[types.USER_FACILITY_LOCATIONS_BY_FACILITY_ID] (state, payload) {
state.facilityLocationsByFacilityId[payload.facilityId] = payload.facilityLocations;
[types.USER_FACILITY_LOCATIONS_BY_FACILITY_ID] (state, facilityLocations) {
Object.keys(facilityLocations).map((facilityId: any) => {
state.facilityLocationsByFacilityId[facilityId] = facilityLocations[facilityId];
})
},
[types.USER_CURRENT_FIELD_MAPPING_UPDATED] (state, payload) {
state.currentMapping = payload
Expand Down
8 changes: 4 additions & 4 deletions src/views/InventoryDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<ion-chip outline class="tablet location">
<ion-icon :icon="locationOutline" />
<ion-select interface="popover" :value="item.locationSeqId" @ionChange="setFacilityLocation($event, item)">
<ion-select-option v-for="facilityLocation in getFacilityLocationsByFacilityId(item.externalFacilityId ? item.externalFacilityId : item.facilityId)" :key="facilityLocation.locationSeqId" :value="facilityLocation.locationSeqId" >{{ facilityLocation.locationSeqId }}</ion-select-option>
<ion-select-option v-for="facilityLocation in getFacilityLocationsByFacilityId(item.externalFacilityId ? item.externalFacilityId : item.facilityId)" :key="facilityLocation.locationSeqId" :value="facilityLocation.locationSeqId" >{{ facilityLocation.locationPath }}</ion-select-option>
</ion-select>
</ion-chip>

Expand Down Expand Up @@ -347,11 +347,11 @@ export default defineComponent({
async apply() {
if(this.facilityId) {
const facilityLocations = await this.store.dispatch('user/fetchFacilityLocations', [this.facilityId]);
await this.stock.parsed.map((item: any) => {
const locationSeqId = facilityLocations[this.facilityId] && facilityLocations[this.facilityId][0] && facilityLocations[this.facilityId][0].locaionSeqId ? facilityLocations[this.facilityId][0].locaionSeqId : '';
this.stock.parsed.map((item: any) => {
if (item.isSelected) {
item.facilityId = this.facilityId;
//TODO: Need to improve the handling of locationSeqId.
item.locationSeqId = facilityLocations && facilityLocations[0] && facilityLocations[0].locationSeqId ? facilityLocations[0].locationSeqId : "";
item.locationSeqId = locationSeqId;
item.externalFacilityId = "";
}
})
Expand Down

0 comments on commit 8a70310

Please sign in to comment.