Skip to content

Commit

Permalink
OLMIS-7793: Changed AMC calculation for SM facilities (#93)
Browse files Browse the repository at this point in the history
* OLMIS-7793: Test checking AMC for submitting requisition in SM

* OLMIS-7793: Fixed AMC calculation for submit

* OLMIS-7793: Adjusted tests to match changed submit method

* OLMIS-7793: Changed AMC calculation for authorize, approve and reject

* OLMIS-7793: Adjusted comments and formatting

* OLMIS-7793: Changed calculate stock fields methods to SM

* OLMIS-7793: Initial requisition refactor

* OLMIS-7793: Adjusted tests after code refactor

* OLMIS-7793: Fixed a bug in calculations

* OLMIS-7793: Removed no longer valid code

* OLMIS-7793: Changed stockCardRangeSummaryForAverage fetching behaviour for a single period

* OLMIS-7793: Code adjustments after a review
  • Loading branch information
anawrotsoldevelo authored Mar 28, 2024
1 parent fcd98f8 commit 1aa4414
Show file tree
Hide file tree
Showing 18 changed files with 696 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@
import org.openlmis.requisition.domain.requisition.StockAdjustment;
import org.openlmis.requisition.domain.requisition.StockAdjustmentDataBuilder;
import org.openlmis.requisition.dto.OrderableDto;
import org.openlmis.requisition.dto.ProcessingPeriodDto;
import org.openlmis.requisition.dto.VersionIdentityDto;
import org.openlmis.requisition.repository.custom.DefaultRequisitionSearchParams;
import org.openlmis.requisition.repository.custom.RequisitionSearchParams;
import org.openlmis.requisition.service.PeriodService;
import org.openlmis.requisition.service.RequisitionService;
import org.openlmis.requisition.testutils.AvailableRequisitionColumnDataBuilder;
import org.openlmis.requisition.testutils.DefaultRequisitionSearchParamsDataBuilder;
import org.openlmis.requisition.testutils.ProcessingPeriodDtoDataBuilder;
import org.openlmis.requisition.testutils.StatusChangeDataBuilder;
import org.openlmis.requisition.utils.Pagination;
import org.slf4j.profiler.Profiler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -94,16 +99,26 @@ public class RequisitionRepositoryIntegrationTest
private Pageable pageRequest = PageRequest.of(
Pagination.DEFAULT_PAGE_NUMBER, Pagination.NO_PAGINATION);

private Profiler profiler;

@Autowired
private AvailableRequisitionColumnRepository availableRequisitionColumnRepository;

@Autowired
private RequisitionService requisitionService;

@Autowired
private PeriodService periodService;


@Before
public void setUp() {
testTemplate = templateRepository.save(new RequisitionTemplateDataBuilder().build());
requisitions = new ArrayList<>();
for (int count = 0; count < 5; ++count) {
requisitions.add(repository.save(generateInstance()));
}
profiler = new Profiler("TEST_PROFILER");
}

@Test
Expand Down Expand Up @@ -766,6 +781,9 @@ private void searchByProgramSupervisoryNodePairsShouldSortByAuthorizedDate(Direc
final UUID user = UUID.randomUUID();
final Map<VersionIdentityDto, OrderableDto> products = emptyMap();

final ProcessingPeriodDto period = new ProcessingPeriodDtoDataBuilder()
.buildAsDto();

Requisition matchingRequisition1 = requisitions.get(0);
matchingRequisition1.setProgramId(programId);
matchingRequisition1.setSupervisoryNodeId(supervisoryNodeId);
Expand All @@ -790,41 +808,53 @@ private void searchByProgramSupervisoryNodePairsShouldSortByAuthorizedDate(Direc
// to verify that the latest authorized status change is used for comparison
// 2) we have to save requisitions after each status change because the createdDate field
// is set by hibernate - because of @PrePersist annotation in the BaseTimestampedEntity
matchingRequisition1.submit(products, user, false);
matchingRequisition1.submit(
products, user, false, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition1);

matchingRequisition2.submit(products, user, false);
matchingRequisition2.submit(
products, user, false, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition2);

matchingRequisition3.submit(products, user, false);
matchingRequisition3.submit(
products, user, false, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition3);

matchingRequisition1.authorize(products, user);
matchingRequisition1.authorize(
products, user, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition1);

matchingRequisition2.authorize(products, user);
matchingRequisition2.authorize(
products, user, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition2);

matchingRequisition3.authorize(products, user);
matchingRequisition3.authorize(
products, user, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition3);

matchingRequisition2.reject(products, user);
matchingRequisition2.reject(
products, user, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition2);

matchingRequisition3.reject(products, user);
matchingRequisition3.reject(
products, user, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition3);

matchingRequisition3.submit(products, user, false);
matchingRequisition3.submit(
products, user, false, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition3);

matchingRequisition2.submit(products, user, false);
matchingRequisition2.submit(
products, user, false, period, requisitionService, periodService, profiler);
saveAndFlushWithDelay(matchingRequisition2);

matchingRequisition3.authorize(products, user);
matchingRequisition3.authorize(
products, user, period, requisitionService, periodService, profiler);
matchingRequisition3.setSupervisoryNodeId(supervisoryNodeId);
saveAndFlushWithDelay(matchingRequisition3);

matchingRequisition2.authorize(products, user);
matchingRequisition2.authorize(
products, user, period, requisitionService, periodService, profiler);
matchingRequisition2.setSupervisoryNodeId(supervisoryNodeId);
saveAndFlushWithDelay(matchingRequisition2);

Expand Down
Loading

0 comments on commit 1aa4414

Please sign in to comment.