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: common admin permission on ship now button if any shipment package require tracking (#281) #289

Merged
merged 7 commits into from
Oct 30, 2023
1 change: 1 addition & 0 deletions src/authorization/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default {
"APP_UPDT_ECOM_INV_CONFIG": "APP_UPDT_ECOM_INV_CONFIG",
"APP_UNPACK_ORDER": "APP_UNPACK_ORDER",
"APP_RECYCLE_ORDER": "APP_RECYCLE_ORDER",
"APP_FORCE_SHIP_ORDER": "APP_FORCE_SHIP_ORDER"
}
1 change: 1 addition & 0 deletions src/authorization/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default {
"APP_UNPACK_ORDER": "COMMON_ADMIN",
"APP_RECYCLE_ORDER": "COMMON_ADMIN",
"APP_STOREFULFILLMENT_ADMIN": "STOREFULFILLMENT_ADMIN",
"APP_FORCE_SHIP_ORDER": "COMMON_ADMIN"
} as any
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"No capacity sets the fulfillment capacity to 0, preventing any new orders from being allocated to this facility. Use the \"Reject all orders\" option in the fulfillment pages to clear your facilities fulfillment queue. To add a fulfillment capacity to this facility, use the custom option.": "No capacity sets the fulfillment capacity to 0, preventing any new orders from being allocated to this facility. Use the \"Reject all orders\" option in the fulfillment pages to clear your facilities fulfillment queue. {space}To add a fulfillment capacity to this facility, use the custom option.",
"No new file upload. Please try again": "No new file upload. Please try again",
"No fulfillment capacity": "No fulfillment capacity",
"No orders are currently able to be shipped due to missing tracking codes.": "No orders are currently able to be shipped due to missing tracking codes.",
"No reason": "No reason",
"No results found for . Try searching Open or Completed tab instead. If you still can't find what you're looking for, try switching stores.": "No results found for { searchedQuery }. Try searching Open or Completed tab instead.{ lineBreak } If you still can't find what you're looking for, try switching stores.",
"No results found for . Try searching In Progress or Open tab instead. If you still can't find what you're looking for, try switching stores.": "No results found for { searchedQuery }. Try searching In Progress or Open tab instead.{ lineBreak } If you still can't find what you're looking for, try switching stores.",
Expand Down Expand Up @@ -160,6 +161,7 @@
"Order updated successfully": "Order updated successfully",
"orders": "orders",
"Out of stock": "Out of stock",
"out of cannot be shipped due to missing tracking codes.": "{remainingOrders} out of {totalOrders} cannot be shipped due to missing tracking codes.",
"package": "package",
"packages": "packages",
"Pack": "Pack",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"No data available!": "No data available!",
"No data Found.": "No data Found.",
"No new file upload. Please try again": "No se cargó ningún archivo nuevo. Por favor, inténtalo nuevamente.",
"No orders are currently able to be shipped due to missing tracking codes.": "No orders are currently able to be shipped due to missing tracking codes.",
"No reason": "Sin motivo",
"No results found for . Try searching Open or Completed tab instead. If you still can't find what you're looking for, try switching stores.": "No results found for { searchedQuery }. Try searching Open or Completed tab instead.{ lineBreak }If you still can't find what you're looking for, try switching stores.",
"No results found for . Try searching In Progress or Open tab instead. If you still can't find what you're looking for, try switching stores.": "No results found for { searchedQuery }. Try searching In Progress or Open tab instead.{ lineBreak } If you still can't find what you're looking for, try switching stores.",
Expand Down Expand Up @@ -160,6 +161,7 @@
"Order updated successfully": "Pedido actualizado exitosamente",
"orders": "pedidos",
"Out of stock": "Agotado",
"out of cannot be shipped due to missing tracking codes.": "{remainingOrders} out of {totalOrders} cannot be shipped due to missing tracking codes.",
"package": "paquete",
"packages": "paquetes",
"Pack": "Empacar",
Expand Down
2 changes: 1 addition & 1 deletion src/services/OrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const fetchShipmentPackages = async (shipmentIds: Array<string>): Promise<any> =
"trackingCode_op": "empty",
"shipmentItemSeqId_op": "not-empty"
},
"fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId"],
"fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId", "isTrackingRequired"],
"viewSize": 250, // maximum records we could have
"distinct": "Y"
}
Expand Down
38 changes: 30 additions & 8 deletions src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
</ion-item>
</div>
<div class="results">
<ion-button :disabled="!hasAnyPackedShipment() || hasAnyMissingInfo()" expand="block" class="bulk-action desktop-only" fill="outline" size="large" @click="bulkShipOrders()">{{ translate("Ship") }}</ion-button>

<ion-button :disabled="!hasPermission(Actions.APP_FORCE_SHIP_ORDER)" expand="block" class="bulk-action desktop-only" fill="outline" size="large" @click="bulkShipOrders()">{{ translate("Ship") }}</ion-button>
<ion-card class="order" v-for="(order, index) in getCompletedOrders()" :key="index">
<div class="order-header">
<div class="order-primary-info">
Expand Down Expand Up @@ -93,7 +92,7 @@
<!-- TODO: implement functionality to mobile view -->
<div class="mobile-only">
<ion-item>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || (isTrackingRequiredForAnyShipmentPackage(order) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" fill="clear" >{{ translate("Ship Now") }}</ion-button>
<ion-button slot="end" fill="clear" color="medium" @click="shippingPopover">
<ion-icon slot="icon-only" :icon="ellipsisVerticalOutline" />
</ion-button>
Expand All @@ -104,7 +103,7 @@
<div class="actions">
<div class="desktop-only">
<ion-button v-if="!hasPackedShipments(order)" :disabled="true">{{ translate("Shipped") }}</ion-button>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo" @click="shipOrder(order)" v-else>{{ translate("Ship Now") }}</ion-button>
<ion-button v-else :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo || (isTrackingRequiredForAnyShipmentPackage(order) && !hasPermission(Actions.APP_FORCE_SHIP_ORDER))" @click="shipOrder(order)">{{ translate("Ship Now") }}</ion-button>
<ion-button :disabled="order.hasMissingShipmentInfo || order.hasMissingPackageInfo" fill="outline" @click="regenerateShippingLabel(order)">
{{ translate("Regenerate Shipping Label") }}
<ion-spinner color="primary" slot="end" v-if="order.isGeneratingShippingLabel" name="crescent" />
Expand All @@ -125,9 +124,8 @@
</ion-infinite-scroll>
</div>
</div>
<!-- TODO: make mobile view functional -->
<ion-fab v-if="completedOrders.total" class="mobile-only" vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="bulkShipOrders()">
<ion-fab-button :disabled="!hasAnyPackedShipment() || hasAnyMissingInfo() || !hasPermission(Actions.APP_FORCE_SHIP_ORDER)" @click="bulkShipOrders()">
<ion-icon :icon="checkmarkDoneOutline" />
</ion-fab-button>
</ion-fab>
Expand Down Expand Up @@ -331,6 +329,21 @@ export default defineComponent({
text: translate("Ship"),
handler: async () => {
let orderList = JSON.parse(JSON.stringify(this.completedOrders.list))
// orders with tracking required and missing label must be excluded
const trackingRequiredOrders = orderList.filter((order: any) => this.isTrackingRequiredForAnyShipmentPackage(order))
let trackingRequiredAndMissingLabelOrders: any
if (trackingRequiredOrders.length) {
// filtering and excluding orders having missing label image with tracking required
trackingRequiredAndMissingLabelOrders = trackingRequiredOrders.filter((order: any) => order.missingLabelImage).map((order: any) => order.orderId)
if (trackingRequiredAndMissingLabelOrders.length) {
orderList = orderList.filter((order: any) => !trackingRequiredAndMissingLabelOrders.includes(order.orderId))
}
}

if (!orderList.length) {
showToast(translate("No orders are currently able to be shipped due to missing tracking codes."))
return;
}

let shipmentIds = orderList.reduce((shipmentIds: any, order: any) => {
if (order.shipments) {
Expand Down Expand Up @@ -359,8 +372,10 @@ export default defineComponent({
try {
const resp = await OrderService.bulkShipOrders(payload)

if(resp.status == 200 && !hasError(resp)) {
showToast(translate('Orders shipped successfully'))
if (resp.status == 200 && !hasError(resp)) {
!trackingRequiredAndMissingLabelOrders.length
? showToast(translate('Orders shipped successfully'))
: showToast(translate('out of cannot be shipped due to missing tracking codes.', { remainingOrders: trackingRequiredAndMissingLabelOrders.length, totalOrders: packedOrdersCount }))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
: showToast(translate('out of cannot be shipped due to missing tracking codes.', { remainingOrders: trackingRequiredAndMissingLabelOrders.length, totalOrders: packedOrdersCount }))
: showToast(translate('out of orders cannot be shipped due to missing tracking codes.', { remainingOrders: trackingRequiredAndMissingLabelOrders.length, totalOrders: packedOrdersCount }))

// TODO: handle the case of data not updated correctly
await Promise.all([this.initialiseOrderQuery(), this.fetchShipmentMethods(), this.fetchCarrierPartyIds()]);
} else {
Expand Down Expand Up @@ -609,6 +624,13 @@ export default defineComponent({
},
fetchProductStock(productId: string) {
this.store.dispatch('stock/fetchStock', { productId })
},
isTrackingRequiredForAnyShipmentPackage(order: any) {
if (!order.shipmentPackages) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the length of shipment packages.

return false
}

return order.shipmentPackages.some((shipmentPackage: any) => shipmentPackage.isTrackingRequired === 'Y')
}
},
setup() {
Expand Down
Loading