Skip to content

Commit

Permalink
Merge pull request #246 from hotwax/242_create_product_facility_record
Browse files Browse the repository at this point in the history
Improved: workflow to create a ProductFacility assoc from the app if a user tries to save a product count to their list where the product is not associated with the facility (#242).
  • Loading branch information
ravilodhi authored Dec 27, 2023
2 parents 1fe896b + fc61fb2 commit c19d840
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/services/ProductService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { api } from '@/adapter';
import { hasError } from "@/utils";

const fetchProducts = async (query: any): Promise <any> => {
return api({
Expand Down Expand Up @@ -34,9 +35,45 @@ const updateVariance = async (query: any): Promise<any> => {
})
}

const isProductFacilityAssocExists = async (productId: string, facilityId: string): Promise<any> => {
try {

const resp = await api({
url: 'performFind',
method: 'POST',
data: {
"inputFields": {
facilityId: facilityId,
productId: productId,
},
"viewSize": 1,
"entityName": "ProductFacility",
"fieldList": ["productId", "facilityId"],
noConditionFind: 'Y'
}
}) as any
if (!hasError(resp) && resp.data.docs.length) {
return true
}
return false
} catch (err) {
return false
}
}

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

export const ProductService = {
addProductToFacility,
fetchProducts,
importInventoryCount,
isProductFacilityAssocExists,
getFacilityLocations,
updateVariance
}
17 changes: 17 additions & 0 deletions src/views/count.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
if (this.quantity) {
this.product.quantity = this.quantity;
this.product.availableQOH = this.availableQOH;
//Create the ProductFacility record if it does not exist.
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,6 +234,21 @@
showToast(translate("Enter the stock count for the product"))
}
},
async checkAndCreateProductFacilityAssoc() {
try {
if (!await ProductService.isProductFacilityAssocExists(this.product.productId, this.facility.facilityId)) {
const resp = await ProductService.addProductToFacility({
productId: this.product.productId,
facilityId: this.facility.facilityId
});
if (hasError(resp)) {
throw resp.data;
}
}
} catch (err) {
console.error(err);
}
},
async getInventory() {
if (!this.product.locationId) {
console.warn("There are no facility locations, skipping fetching the inventory");
Expand Down

0 comments on commit c19d840

Please sign in to comment.