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: 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). #246

Merged
merged 1 commit into from
Dec 27, 2023
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
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
Loading