Skip to content

Commit

Permalink
Merge pull request #4411 from openboxes/obgm-0.8.23-hotfix1
Browse files Browse the repository at this point in the history
Cherry pick changes from the 0.8.23 Hotfix 1 to the obgm feature branch
  • Loading branch information
awalkowiak committed Dec 12, 2023
2 parents 660524b + 8a24aa5 commit 8c0fb05
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ class StockMovementApiController {
// TODO: Tech huddle around this area (if looking into currentLocation in API like that is ok)
def currentLocation = Location.get(session?.warehouse?.id)
if (stockMovement.isDeleteOrRollbackAuthorized(currentLocation)) {
// If a shipment has items with invoice quantity greater than 0,
// it means there is a connected invoice, and we cannot delete stock movement
if (stockMovement?.shipment?.hasInvoicedItem()) {
String message = g.message(
code: 'stockMovement.delete.error.message',
default: 'The Stock Movement could not be deleted'
)
response.status = 400
render([errorMessage: message] as JSON)
return
}

if (stockMovement?.isPending() || !stockMovement?.shipment?.currentStatus) {
try {
stockMovementService.deleteStockMovement(stockMovement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ class StockMovementController {
(!isRequestedUrlForStockRequest && stockMovement.electronicType)) {
throw new IllegalAccessException("You can't delete the stock movement: ${stockMovement.name} using this URL")
}

// If a shipment has items with invoice quantity greater than 0,
// it means there is a connected invoice, and we cannot delete stock movement
if (stockMovement?.shipment?.hasInvoicedItem()) {
flash.message = g.message(
code: 'stockMovement.delete.error.message',
default: 'The Stock Movement could not be deleted',
)
redirect(action: "show", id: params.id)
return
}

if (stockMovement.isDeleteOrRollbackAuthorized(currentLocation)) {
if (stockMovement?.shipment?.currentStatus == ShipmentStatusCode.PENDING || !stockMovement?.shipment?.currentStatus) {
try {
Expand Down
2 changes: 1 addition & 1 deletion grails-app/domain/org/pih/warehouse/order/OrderItem.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class OrderItem implements Serializable, Comparable<OrderItem> {
}

def getInvoices() {
return invoiceItems*.invoice.unique()
return allInvoiceItems*.invoice.unique()
}

Boolean getHasInvoices() {
Expand Down
4 changes: 4 additions & 0 deletions grails-app/domain/org/pih/warehouse/shipping/Shipment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -671,5 +671,9 @@ class Shipment implements Comparable, Serializable {
Event event = events.find { Event event -> event?.eventType?.eventCode == EventCode.CUSTOMS_RELEASE }
return event?.eventDate
}

boolean hasInvoicedItem() {
shipmentItems.any { it.quantityInvoiced > 0 }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ShipmentItem implements Comparable, Serializable {

static transients = ["comments", "orderItemId", "quantityReceivedAndCanceled", "quantityCanceled", "quantityReceived", "quantityRemaining",
"orderNumber", "orderId", "purchaseOrders", "orderName", "quantityRemainingToShip", "quantityPerUom", "hasRecalledLot", "quantityPicked", "quantityPickedFromOrders",
"unavailableQuantityPicked", "paymentTerm"]
"unavailableQuantityPicked", "paymentTerm", "quantityInvoiced"]

static mapping = {
id generator: 'uuid'
Expand Down Expand Up @@ -256,8 +256,8 @@ class ShipmentItem implements Comparable, Serializable {
return inventoryItem?.lotStatus == LotStatusCode.RECALLED
}

int getQuantityInvoiced() {
return invoiceItems.sum { it.quantity ?: 0 }
Integer getQuantityInvoiced() {
return invoiceItems?.sum { it.quantity ?: 0 }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.pih.warehouse.product.ProductAssociationTypeCode
import org.pih.warehouse.receiving.ReceiptItem
import org.pih.warehouse.requisition.ReplenishmentTypeCode
import org.pih.warehouse.requisition.Requisition
import org.pih.warehouse.requisition.RequisitionDataService
import org.pih.warehouse.requisition.RequisitionItem
import org.pih.warehouse.requisition.RequisitionItemSortByCode
import org.pih.warehouse.requisition.RequisitionItemStatus
Expand Down Expand Up @@ -86,6 +87,7 @@ class StockMovementService {
def forecastingService
def outboundStockMovementService
UserService userService
RequisitionDataService requisitionDataService

GrailsApplication grailsApplication

Expand Down Expand Up @@ -263,8 +265,7 @@ class StockMovementService {
void updateRequisitionStatus(String id, RequisitionStatus status, Comment comment = null) {

log.info "Update status ${id} " + status
// TODO: In Grails the get below should be replaced by the data service get that joins the Events
Requisition requisition = Requisition.get(id)
Requisition requisition = requisitionDataService.getRequisitionWithEvents(id)
if (status == RequisitionStatus.CHECKING) {
Shipment shipment = requisition.shipment
shipment?.expectedShippingDate = new Date()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.pih.warehouse.requisition

import grails.gorm.services.Join
import grails.gorm.services.Service

@Service(Requisition)
interface RequisitionDataService {

void delete(String id)

Requisition save(Requisition requisition)

Requisition get(String id)

@Join("events")
Requisition getRequisitionWithEvents(String id)
}

0 comments on commit 8c0fb05

Please sign in to comment.