Skip to content

Commit

Permalink
Merge pull request #322 from ymaheshwari1/fulfillment/#313
Browse files Browse the repository at this point in the history
Improved: code to have support for storing stock by facility(#313)
  • Loading branch information
ravilodhi authored Oct 20, 2023
2 parents ebc7b68 + a6fac16 commit a805788
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ const actions: ActionTree<OrderState, RootState> = {
groupBy: 'shipGroupSeqId',
filters: {
'-shipGroupSeqId': { value: order.items[0].shipGroupSeqId },
'-shipmentMethodTypeId': { value: 'STOREPICKUP' },
orderId: { value: order.orderId }
},
docType: 'ORDER'
Expand Down Expand Up @@ -603,7 +602,6 @@ const actions: ActionTree<OrderState, RootState> = {
groupBy: 'shipGroupSeqId',
filters: {
'shipGroupSeqId': { value: shipGroupSeqIds },
'-shipmentMethodTypeId': { value: 'STOREPICKUP' },
'-fulfillmentStatus': { value: ['Rejected', 'Cancelled'] },
orderId: { value: orderId }
}
Expand Down
7 changes: 4 additions & 3 deletions src/store/modules/stock/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import { showToast } from '@/utils'
import { translate } from '@hotwax/dxp-components'

const actions: ActionTree<StockState, RootState> = {
async fetchStock({ commit }, { productId }) {
async fetchStock({ commit }, { productId, facilityId = '' }) {
const id = facilityId ? facilityId : this.state.user.currentFacility.facilityId

try {
const payload = {
productId,
facilityId: this.state.user.currentFacility.facilityId
facilityId: id
}

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: id, 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
Expand Up @@ -3,8 +3,10 @@ import StockState from './StockState'
import RootState from '../../RootState'

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

return state.products[productId] ? state.products[productId][id] ? state.products[productId][id] : {} : {}
}
}
export default getters;
8 changes: 7 additions & 1 deletion src/store/modules/stock/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import * as types from './mutation-types'

const mutations: MutationTree <StockState> = {
[types.STOCK_ADD_PRODUCT] (state, payload) {
state.products[payload.productId] = payload.stock
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;
10 changes: 5 additions & 5 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@
<p class="overline">{{ getProduct(item.productId).sku }}</p>
{{ getProduct(item.productId).parentProductName }}
</ion-label>
<!-- TODO: add a spinner if the api takes too long to fetch the stock -->
<!-- TODO: add a spinner if the api takes too long to fetch the stock -->
<div slot="end" class="product-metadata">
<ion-note v-if="getProductStock(item.productId).quantityOnHandTotal">{{ getProductStock(item.productId).quantityOnHandTotal }} {{ translate('pieces in stock') }}</ion-note>
<ion-button fill="clear" v-else size="small" @click.stop="fetchProductStock(item.productId)">
<ion-note v-if="getProductStock(item.productId, item.facilityId).quantityOnHandTotal">{{ getProductStock(item.productId, item.facilityId).quantityOnHandTotal }} {{ translate('pieces in stock') }}</ion-note>
<ion-button fill="clear" v-else size="small" @click.stop="fetchProductStock(item.productId, item.facilityId)">
<ion-icon color="medium" slot="icon-only" :icon="cubeOutline"/>
</ion-button>
</div>
Expand Down Expand Up @@ -373,8 +373,8 @@ export default defineComponent({
});
return popover.present();
},
fetchProductStock(productId: string) {
this.store.dispatch('stock/fetchStock', { productId })
fetchProductStock(productId: string, facilityId = '') {
this.store.dispatch('stock/fetchStock', { productId, facilityId })
},
async packOrder(order: any) {
const confirmPackOrder = await alertController
Expand Down

0 comments on commit a805788

Please sign in to comment.