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

Implemented: logic to remove rejected order items from state manually (#638) #698

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
// fetching the additional information like shipmentRoute, carrierParty information
// If no orders then no need to fetch any additional information
if(orders.length){
dispatch('fetchInProgressOrdersAdditionalInformation');
await dispatch('fetchInProgressOrdersAdditionalInformation');
}

emitter.emit('dismissLoader');
Expand All @@ -331,6 +331,14 @@
commit(types.ORDER_INPROGRESS_UPDATED, {orders, total: state.inProgress.total})
},

updateAllInProgressOrder ({ commit, state }, payload) {
const inProgressQuery = JSON.parse(JSON.stringify(state.inProgress.query))

inProgressQuery.viewSize = payload.total
commit(types.ORDER_INPROGRESS_QUERY_UPDATED, { ...inProgressQuery })
commit(types.ORDER_INPROGRESS_UPDATED, payload)
},

// get open orders
async findOpenOrders ({ commit, state }, payload = {}) {
emitter.emit('presentLoader');
Expand Down Expand Up @@ -898,7 +906,7 @@
try {
resp = await OrderService.findOrderShipGroup(orderQueryPayload);
if (resp.status === 200 && !hasError(resp) && resp.data.grouped?.shipGroupSeqId.matches > 0) {
total = resp.data.grouped.shipGroupSeqId.ngroups

Check warning on line 909 in src/store/modules/order/actions.ts

View workflow job for this annotation

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

'total' is assigned a value but never used

Check warning on line 909 in src/store/modules/order/actions.ts

View workflow job for this annotation

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

'total' is assigned a value but never used
shipGroups = resp.data.grouped.shipGroupSeqId.groups

// creating the key as orders as the product information action accept only the orders as a param
Expand Down
47 changes: 44 additions & 3 deletions src/views/InProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@ export default defineComponent({

// creating updated data for items
const rejectedOrderItems = [] as any;
const rejectedProductIds = [] as any;
const rejectedItems = [] as any;
items.map((item: any, index: number) => {
const shipmentPackage = order.shipmentPackages.find((shipmentPackage: any) => shipmentPackage.packageName === item.selectedBox)

Expand All @@ -751,6 +753,9 @@ export default defineComponent({
"shipmentItemSeqId": item.shipmentItemSeqId,
"reason": item.rejectReason
})

if(!rejectedProductIds.includes(item.productId)) rejectedProductIds.push(item.productId);
if(!rejectedItems.includes(`${item.orderId}-${item.orderItemSeqId}`)) rejectedItems.push(`${item.orderId}-${item.orderItemSeqId}`);
//prefix = 'rej'
//form.append(`${prefix}_rejectionReason_${index}`, item.rejectReason)
} else {
Expand Down Expand Up @@ -804,7 +809,8 @@ export default defineComponent({

if(!hasError(resp)) {
if (order.hasRejectedItem) {
this.updateOrderQuery()
await this.updateOrderQuery()
this.removeRejectedOrder(rejectedProductIds, rejectedItems);
} else {
order.isModified = false;

Expand Down Expand Up @@ -832,6 +838,37 @@ export default defineComponent({
logger.error('Failed to update order', err)
}
},
removeRejectedOrder(rejectedProductIds: any, rejectedItems: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can take some alternate route here. On rejection we are refetching in progress orders. Rejected items won't be associated with any shipment. So if we could use that to filter out the rejected order(all items rejected) or the rejected items. This way we can keep the logic in the fetchInProgressOrdersAdditionalInformation action itself.

const orders = JSON.parse(JSON.stringify(this.getInProgressOrders()))
const updatedOrders = orders.filter((order: any) => {
let rejectWholeOrder = false;

// If the EntireOrderRejection setting is true, check if any item in the order needs rejection
if(this.isEntierOrderRejectionEnabled()) {
rejectWholeOrder = order.items.some((item: any) => rejectedItems.includes(`${item.orderId}-${item.orderItemSeqId}`));
}

// If both collateralRejection and entireOrderRejection settings are true, reject the whole order if any item matches the productId
if(this.isEntierOrderRejectionEnabled() && (this.collateralRejectionConfig?.settingValue === 'true')) {
rejectWholeOrder = order.items.some((item: any) => rejectedProductIds.includes(item.productId))
}

// If the EntireRejection setting is true and any item in the order needs rejection, remove the order
if(rejectWholeOrder) return false;

// If the CollateralRejection setting is true, reject all items with the same productId
if(this.collateralRejectionConfig?.settingValue === 'true') {
order.items = order.items.filter((item: any) => !rejectedProductIds.includes(item.productId));
}

// Otherwise, reject only the specific items
order.items = order.items.filter((item: any) => !rejectedItems.includes(`${order.orderId}-${item.orderItemSeqId}`));

// Keep the order if it still has items
return order.items.length > 0;
})
this.store.dispatch("order/updateAllInProgressOrder", { orders: updatedOrders, total: updatedOrders.length })
},
save(order: any) {
if(order.hasRejectedItem) {
const itemsToReject = order.items.filter((item: any) => item.rejectReason)
Expand All @@ -850,8 +887,12 @@ export default defineComponent({
order.hasRejectedItem = true
this.store.dispatch('order/updateInProgressOrder', order)
},
isEntierOrderRejectionEnabled(order: any) {
return (!this.partialOrderRejectionConfig || !this.partialOrderRejectionConfig.settingValue || !JSON.parse(this.partialOrderRejectionConfig.settingValue)) && order.hasRejectedItem
isEntierOrderRejectionEnabled(order?: any) {
if(order) {
return (!this.partialOrderRejectionConfig || !this.partialOrderRejectionConfig.settingValue || !JSON.parse(this.partialOrderRejectionConfig.settingValue)) && order.hasRejectedItem
}

return (!this.partialOrderRejectionConfig || !this.partialOrderRejectionConfig.settingValue || !JSON.parse(this.partialOrderRejectionConfig.settingValue))
},
updateBox(updatedBox: string, item: any, order: any) {
item.selectedBox = updatedBox;
Expand Down
Loading