Skip to content

Commit

Permalink
Merge pull request #331 from ymaheshwari1/bopis/fix-inventory
Browse files Browse the repository at this point in the history
Fixed: support to display the stock for product as per the facility selected and removed unused mutations and types
  • Loading branch information
ravilodhi authored Nov 2, 2023
2 parents e5fd103 + 46e05e4 commit e7b6ce8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/store/modules/stock/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const actions: ActionTree<StockState, RootState> = {

const resp: any = await StockService.getInventoryAvailableByFacility(payload);
if (!hasError(resp)) {
commit(types.STOCK_ADD_PRODUCT, { productId: payload.productId, stock: resp.data })
commit(types.STOCK_ADD_PRODUCT, { productId: payload.productId, facilityId: this.state.user.currentFacility.facilityId, stock: resp.data })
} else {
throw resp.data;
}
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/stock/getters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { GetterTree } from 'vuex'
import StockState from './StockState'
import RootState from '../../RootState'
import store from '@/store'

const getters: GetterTree <StockState, RootState> = {
getProductStock: (state) => (productId: string) => {
return state.products[productId] ? state.products[productId] : {}
getProductStock: (state, RootState) => (productId: any) => {

Check warning on line 7 in src/store/modules/stock/getters.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'RootState' is defined but never used

Check warning on line 7 in src/store/modules/stock/getters.ts

View workflow job for this annotation

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

'RootState' is defined but never used
const facilityId = store.state.user?.currentFacility?.facilityId
return state.products[productId] ? state.products[productId][facilityId] ? state.products[productId][facilityId] : {} : {}
}
}
export default getters;
3 changes: 1 addition & 2 deletions src/store/modules/stock/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const SN_STOCK = 'stock'
export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT'
export const STOCK_ADD_PRODUCTS = SN_STOCK + '/ADD_PRODUCTS'
export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT'
13 changes: 7 additions & 6 deletions src/store/modules/stock/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as types from './mutation-types'

const mutations: MutationTree <StockState> = {
[types.STOCK_ADD_PRODUCT] (state, payload) {
state.products[payload.productId] = payload.stock
},
[types.STOCK_ADD_PRODUCTS] (state, payload) {
payload.products.forEach((product: any) => {
state.products[product.productId] = product.atp
});
if(state.products[payload.productId]) {
state.products[payload.productId][payload.facilityId] = payload.stock
} else {
state.products[payload.productId] = {
[payload.facilityId]: payload.stock
}
}
}
}
export default mutations;

0 comments on commit e7b6ce8

Please sign in to comment.