diff --git a/src/store/modules/stock/actions.ts b/src/store/modules/stock/actions.ts index cc1359831..dbeafee7a 100644 --- a/src/store/modules/stock/actions.ts +++ b/src/store/modules/stock/actions.ts @@ -17,7 +17,7 @@ const actions: ActionTree = { 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; } diff --git a/src/store/modules/stock/getters.ts b/src/store/modules/stock/getters.ts index 3d9b20133..59ebd8f02 100644 --- a/src/store/modules/stock/getters.ts +++ b/src/store/modules/stock/getters.ts @@ -1,10 +1,12 @@ import { GetterTree } from 'vuex' import StockState from './StockState' import RootState from '../../RootState' +import store from '@/store' const getters: GetterTree = { - getProductStock: (state) => (productId: string) => { - return state.products[productId] ? state.products[productId] : {} + getProductStock: (state, RootState) => (productId: any) => { + const facilityId = store.state.user?.currentFacility?.facilityId + return state.products[productId] ? state.products[productId][facilityId] ? state.products[productId][facilityId] : {} : {} } } export default getters; \ No newline at end of file diff --git a/src/store/modules/stock/mutation-types.ts b/src/store/modules/stock/mutation-types.ts index 1b1deb7b7..3937ac90e 100644 --- a/src/store/modules/stock/mutation-types.ts +++ b/src/store/modules/stock/mutation-types.ts @@ -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' \ No newline at end of file +export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT' \ No newline at end of file diff --git a/src/store/modules/stock/mutations.ts b/src/store/modules/stock/mutations.ts index dcd989f37..cc2f3329d 100644 --- a/src/store/modules/stock/mutations.ts +++ b/src/store/modules/stock/mutations.ts @@ -4,12 +4,13 @@ import * as types from './mutation-types' const mutations: MutationTree = { [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; \ No newline at end of file