@Test public void shouldSetDefaultCodeWhenCannotFindACodeForReason(){ StockMovementItem item = new StockMovementItem(); item.setMovementType(MovementReasonManager.MovementType.ISSUE); item.setReason("cannot find a code"); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.DEFAULT_ISSUE)); item.setMovementType(MovementReasonManager.MovementType.RECEIVE); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.DEFAULT_RECEIVE)); item.setMovementType(MovementReasonManager.MovementType.POSITIVE_ADJUST); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT)); item.setMovementType(MovementReasonManager.MovementType.NEGATIVE_ADJUST); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT)); item.setMovementType(MovementReasonManager.MovementType.PHYSICAL_INVENTORY); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.INVENTORY)); item.setReason("physicalInventoryPositive"); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.INVENTORY_POSITIVE)); item.setReason("physicalInventoryNegative"); migrate.setDefaultReasonCode(item); assertThat(item.getReason(), is(MovementReasonManager.INVENTORY_NEGATIVE)); }
protected void setDefaultReasonCode(StockMovementItem item) { if ("physicalInventoryPositive".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_POSITIVE); } else if ("physicalInventoryNegative".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_NEGATIVE); } else { switch (item.getMovementType()) { case ISSUE: item.setReason(MovementReasonManager.DEFAULT_ISSUE); break; case POSITIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT); break; case NEGATIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT); break; case RECEIVE: item.setReason(MovementReasonManager.DEFAULT_RECEIVE); break; case PHYSICAL_INVENTORY: item.setReason(MovementReasonManager.INVENTORY); break; default: throw new RuntimeException("Invalid MovementType :" + item.getMovementType()); } } }
ChangeMovementReasonToCode extends Migration { protected void setDefaultReasonCode(StockMovementItem item) { if ("physicalInventoryPositive".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_POSITIVE); } else if ("physicalInventoryNegative".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_NEGATIVE); } else { switch (item.getMovementType()) { case ISSUE: item.setReason(MovementReasonManager.DEFAULT_ISSUE); break; case POSITIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT); break; case NEGATIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT); break; case RECEIVE: item.setReason(MovementReasonManager.DEFAULT_RECEIVE); break; case PHYSICAL_INVENTORY: item.setReason(MovementReasonManager.INVENTORY); break; default: throw new RuntimeException("Invalid MovementType :" + item.getMovementType()); } } } }
ChangeMovementReasonToCode extends Migration { protected void setDefaultReasonCode(StockMovementItem item) { if ("physicalInventoryPositive".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_POSITIVE); } else if ("physicalInventoryNegative".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_NEGATIVE); } else { switch (item.getMovementType()) { case ISSUE: item.setReason(MovementReasonManager.DEFAULT_ISSUE); break; case POSITIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT); break; case NEGATIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT); break; case RECEIVE: item.setReason(MovementReasonManager.DEFAULT_RECEIVE); break; case PHYSICAL_INVENTORY: item.setReason(MovementReasonManager.INVENTORY); break; default: throw new RuntimeException("Invalid MovementType :" + item.getMovementType()); } } } ChangeMovementReasonToCode(); }
ChangeMovementReasonToCode extends Migration { protected void setDefaultReasonCode(StockMovementItem item) { if ("physicalInventoryPositive".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_POSITIVE); } else if ("physicalInventoryNegative".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_NEGATIVE); } else { switch (item.getMovementType()) { case ISSUE: item.setReason(MovementReasonManager.DEFAULT_ISSUE); break; case POSITIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT); break; case NEGATIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT); break; case RECEIVE: item.setReason(MovementReasonManager.DEFAULT_RECEIVE); break; case PHYSICAL_INVENTORY: item.setReason(MovementReasonManager.INVENTORY); break; default: throw new RuntimeException("Invalid MovementType :" + item.getMovementType()); } } } ChangeMovementReasonToCode(); @Override void up(); }
ChangeMovementReasonToCode extends Migration { protected void setDefaultReasonCode(StockMovementItem item) { if ("physicalInventoryPositive".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_POSITIVE); } else if ("physicalInventoryNegative".equalsIgnoreCase(item.getReason())) { item.setReason(MovementReasonManager.INVENTORY_NEGATIVE); } else { switch (item.getMovementType()) { case ISSUE: item.setReason(MovementReasonManager.DEFAULT_ISSUE); break; case POSITIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_POSITIVE_ADJUSTMENT); break; case NEGATIVE_ADJUST: item.setReason(MovementReasonManager.DEFAULT_NEGATIVE_ADJUSTMENT); break; case RECEIVE: item.setReason(MovementReasonManager.DEFAULT_RECEIVE); break; case PHYSICAL_INVENTORY: item.setReason(MovementReasonManager.INVENTORY); break; default: throw new RuntimeException("Invalid MovementType :" + item.getMovementType()); } } } ChangeMovementReasonToCode(); @Override void up();  }