Skip to content

Commit

Permalink
Improved: added support to create product facility location(#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Feb 6, 2024
1 parent 54aba65 commit 9479a15
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/services/ProductService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,43 @@ const addProductToFacility = async (payload: any): Promise<any> => {
});
}

const getCurrentFacilityLocation = async (facilityId: string): Promise<any> => {
let locationSeqId;
try {
const params = {
"inputFields": {
facilityId
},
"viewSize": 1,
"entityName": "FacilityLocation",
"fieldList": ["areaId", "aisleId", "sectionId", "levelId", "positionId", "locationSeqId"]
}

const resp = await ProductService.getFacilityLocations(params);
if (!hasError(resp) && resp.data.docs.length) {
locationSeqId = resp.data.docs[0].locationSeqId
}
} catch (err) {
console.error(err);
}
return locationSeqId;
}

const createProductFacilityLocation = async (payload: any): Promise<any> => {
return api({
url: "service/createProductFacilityLocation",
method: "post",
data: payload
});
}

export const ProductService = {
addProductToFacility,
createProductFacilityLocation,
fetchProducts,
importInventoryCount,
isProductFacilityAssocExists,
getCurrentFacilityLocation,
getFacilityLocations,
updateVariance
}
21 changes: 18 additions & 3 deletions src/views/count.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@
});
await picker.present();
},
updateProductInventoryCount() {
async updateProductInventoryCount() {
if (this.quantity) {
this.product.quantity = this.quantity;
this.product.availableQOH = this.availableQOH;
//Create the ProductFacility record if it does not exist.
this.checkAndCreateProductFacilityAssoc();
await this.checkAndCreateProductFacilityAssoc();
this.store.dispatch('product/updateInventoryCount', { ...this.product, locationId: this.product.locationId });
showToast(translate("Item added to upload list"), [{
text: translate('View'),
Expand All @@ -232,15 +232,30 @@
}
},
async checkAndCreateProductFacilityAssoc() {
let resp;
try {
if (!await ProductService.isProductFacilityAssocExists(this.product.productId, this.facility.facilityId)) {
const resp = await ProductService.addProductToFacility({
resp = await ProductService.addProductToFacility({
productId: this.product.productId,
facilityId: this.facility.facilityId
});
if (hasError(resp)) {
throw resp.data;
}
const locationSeqId = await ProductService.getCurrentFacilityLocation(this.facility.facilityId)
resp = await ProductService.createProductFacilityLocation({
productId: this.product.productId,
facilityId: this.facility.facilityId,
locationSeqId
});
if (!hasError(resp)) {
await this.getFacilityLocations()
} else {
throw resp.data;
}
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 9479a15

Please sign in to comment.