Commit ad87c9a6 authored by Artem Hrybeniuk's avatar Artem Hrybeniuk
Browse files

Merge branch '249-inventory-action-withdraw' into 'main'

BUG: Withdrawal action needs access to the actual Inventory record

Closes #249

See merge request grin-global/grin-global-server!335
parents d5f2b891 d20b5e2f
......@@ -43,7 +43,7 @@ public class InventoryAction extends AbstractAction<InventoryAction> {
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "inventory_id", nullable = false)
@JoinColumn(name = "inventory_id", nullable = false, updatable = false)
@JsonIdentityReference
@JsonIdentityInfo(scope = Inventory.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIgnoreProperties({ "ownedBy" })
......
......@@ -268,9 +268,10 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
inventoryAction.apply(source);
InventoryAction saved = repository.save(inventoryAction);
if (inventoryAction.getCompletedDate() != null) {
if (CommunityCodeValues.INVENTORY_ACTION_WITHDRAW.value.equals(inventoryAction.getActionNameCode())) {
reduceInventory(inventoryAction);
if (saved.getCompletedDate() != null) {
if (CommunityCodeValues.INVENTORY_ACTION_WITHDRAW.value.equals(saved.getActionNameCode())) {
var updatedInventory = reduceInventory(saved, inventoryRepository.getById(saved.getInventory().getId()));
saved.setInventory(updatedInventory);
}
}
......@@ -281,7 +282,7 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
public InventoryAction update(InventoryAction updated, InventoryAction target) {
if (target.getCompletedDate() == null && updated.getCompletedDate() != null) {
if (CommunityCodeValues.INVENTORY_ACTION_WITHDRAW.value.equals(updated.getActionNameCode())) {
var updatedInventory = reduceInventory(updated);
var updatedInventory = reduceInventory(updated, target.getInventory());
updated.setInventory(updatedInventory);
}
}
......@@ -294,11 +295,9 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
return inventoryRepository.findAll(QInventory.inventory.id.in(id));
}
private Inventory reduceInventory(InventoryAction inventoryAction) {
private Inventory reduceInventory(InventoryAction inventoryAction, Inventory inventory) {
assert(CommunityCodeValues.INVENTORY_ACTION_WITHDRAW.value.equals(inventoryAction.getActionNameCode()));
Inventory inventory = inventoryAction.getInventory();
// if flagged as auto-deducted, reduce quantity on hand
if ("Y".equals(inventory.getIsAutoDeducted())) {
if (!inventory.getQuantityOnHandUnitCode().equals(inventoryAction.getQuantityUnitCode())) {
......
......@@ -357,6 +357,10 @@ public class InventoryActionServiceTest extends AbstractServicesTest {
created.setActionNameCode(CommunityCodeValues.INVENTORY_ACTION_WITHDRAW.value);
created.setCompletedDate(new Date());
created.setCompletedDateCode(CommunityCodeValues.DATE_FORMAT_DATETIME.value);
inventory.setIsAutoDeducted(null);
inventory.setQuantityOnHandUnitCode(null);
inventory.setQuantityOnHand(null);
created.setInventory(inventory);
inventoryActionService.update(created);
inventory = inventoryService.get(inventory.getId());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment