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

Fixed: support to display the stock for product as per the facility selected and removed unused mutations and types #331

Merged
merged 1 commit into from
Nov 2, 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
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 / 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;
Loading