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

Revert "OAM-191: Implement missing backend for stock management for reference to unit of orderables." #50

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

import org.junit.Test;
import org.openlmis.stockmanagement.domain.card.StockCard;
import org.openlmis.stockmanagement.domain.event.CalculatedStockOnHand;
Expand Down Expand Up @@ -69,8 +70,8 @@ private CalculatedStockOnHand generateInstance(UUID facility, UUID program, UUID

StockCard stockCard = new StockCardDataBuilder(event)
.withoutId()
.withOrderableId(product)
.withLotId(lot)
.withOrderable(product)
.withLot(lot)
.build();

stockCard = stockCardRepository.save(stockCard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private StockCard generateInstance(UUID facility, UUID program, UUID product, UU

StockCard stockCard = new StockCardDataBuilder(event)
.withoutId()
.withOrderableId(product)
.withLotId(lot)
.withOrderable(product)
.withLot(lot)
.withLineItem(lineItem)
.withIsActive(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,8 @@ private StockEvent prepareEvent(UUID facility, UUID program) {
private StockCard prepareStockCard(StockEvent event, UUID product, UUID lot) {
StockCard result = new StockCardDataBuilder(event)
.withoutId()
.withOrderableId(product)
.withLotId(lot)
.withOrderable(product)
.withLot(lot)
.build();
return stockCardRepository.save(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ private PhysicalInventoryLineItemDto generatePhysicalInventoryLineItem() {
item.setQuantity(10);
item.setStockOnHand(5);
item.setOrderableId(UUID.randomUUID());
item.setLotId(UUID.randomUUID());
item.setUnitOfOrderableId(UUID.randomUUID());
item.setStockAdjustments(new ArrayList<>());
item.setLotId(UUID.randomUUID());
item.setExtraData(new HashMap<>());

return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ public class StockCard extends BaseEntity implements IdentifiableByOrderableLot

@Column(nullable = false)
private UUID orderableId;

@Column
private UUID lotId;

@Column
private UUID unitOfOrderableId;

@LazyCollection(FALSE)
@OneToMany(cascade = ALL, mappedBy = "stockCard")
private List<StockCardLineItem> lineItems;
Expand Down Expand Up @@ -138,7 +134,6 @@ public static StockCard createStockCardFrom(StockEventDto stockEventDto,
.facilityId(stockEventDto.getFacilityId())
.orderableId(eventLineItem.getOrderableId())
.lotId(eventLineItem.getLotId())
.unitOfOrderableId(eventLineItem.getUnitOfOrderableId())

.lineItems(new ArrayList<>())
.stockOnHand(0)
Expand All @@ -154,7 +149,6 @@ public StockCard shallowCopy() {
StockCard clone = new StockCard();
clone.setId(getId());
clone.setLotId(lotId);
clone.setUnitOfOrderableId(unitOfOrderableId);
clone.setStockOnHand(stockOnHand);
clone.setOrderableId(orderableId);
clone.setProgramId(programId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public class StockCardLineItem extends BaseEntity {
@Column(nullable = false)
private UUID userId;

private UUID unitOfOrderableId;

@Transient
private Integer stockOnHand;

Expand Down Expand Up @@ -177,6 +179,7 @@ public static StockCardLineItem createLineItemFrom(
.signature(eventDto.getSignature())
.userId(eventDto.getContext().getCurrentUserId())

.unitOfOrderableId(eventLineItemDto.getUnitOfOrderableId())
.extraData(eventLineItemDto.getExtraData())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public class PhysicalInventoryLineItem
implements VvmApplicable, IdentifiableByOrderableLot {
@Column(nullable = false)
private UUID orderableId;
@Column
private UUID lotId;
@Column
private UUID unitOfOrderableId;

//when saving draft quantity is allowed to be null
//do NOT annotate this field as nullable = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
public class PhysicalInventoryLineItemDto implements IdentifiableByOrderableLot, VvmApplicable {
private UUID orderableId;
private UUID lotId;
private UUID unitOfOrderableId;
private Integer stockOnHand;
private Integer quantity;
private List<PhysicalInventoryLineItemAdjustment> stockAdjustments;
Expand All @@ -50,9 +49,8 @@ public class PhysicalInventoryLineItemDto implements IdentifiableByOrderableLot,
*/
public PhysicalInventoryLineItem toPhysicalInventoryLineItem(PhysicalInventory inventory) {
return PhysicalInventoryLineItem.builder()
.orderableId(orderableId)
.lotId(lotId)
.unitOfOrderableId(unitOfOrderableId)
.orderableId(getOrderableId())
.lotId(getLotId())
.quantity(quantity)
.stockAdjustments(stockAdjustments)
.extraData(extraData)
Expand All @@ -73,7 +71,6 @@ public static PhysicalInventoryLineItemDto from(PhysicalInventoryLineItem lineIt
.extraData(lineItem.getExtraData())
.orderableId(lineItem.getOrderableId())
.lotId(lineItem.getLotId())
.unitOfOrderableId(lineItem.getUnitOfOrderableId())
.build();
}

Expand All @@ -93,7 +90,6 @@ public static List<PhysicalInventoryLineItemDto> from(List<StockEventLineItemDto
.extraData(lineItem.getExtraData())
.orderableId(lineItem.getOrderableId())
.lotId(lineItem.getLotId())
.unitOfOrderableId(lineItem.getUnitOfOrderableId())
.build())
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public final class StockCardDto implements IdentifiableByOrderableLot {
private ProgramDto program;
private OrderableDto orderable;
private LotDto lot;
private UUID unitOfOrderableId;

private Map<String, String> extraData;
private boolean isActive;

Expand Down Expand Up @@ -104,7 +102,6 @@ public static StockCardDto createFrom(StockCard stockCard) {
.map(StockCardLineItemDto::createFrom).collect(toList()))
.stockOnHand(stockCard.getStockOnHand())
.isActive(stockCard.isActive())
.unitOfOrderableId(stockCard.getUnitOfOrderableId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public final class CanFulfillForMeEntryDto {
@Setter
private ObjectReferenceDto lot;

@Getter
@Setter
private ObjectReferenceDto unitOfOrderable;

@Getter
@Setter
private Integer stockOnHand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class StockCardSummariesV2DtoBuilder {
static final String ORDERABLES = "orderables";
static final String STOCK_CARDS = "stockCards";
static final String LOTS = "lots";
static final String UNIT_OF_ORDERABLES = "unitOfOrderables";

@Value("${service.url}")
private String serviceUrl;
Expand Down Expand Up @@ -105,13 +104,10 @@ private List<CanFulfillForMeEntryDto> buildFulfillsEntries(UUID orderableId,

private CanFulfillForMeEntryDto createCanFulfillForMeEntry(StockCard stockCard,
UUID orderableId) {
UUID lotId = stockCard.getLotId();
UUID unitOfOrderableId = stockCard.getUnitOfOrderableId();
return new CanFulfillForMeEntryDto(
createStockCardReference(stockCard.getId()),
createReference(orderableId, ORDERABLES),
lotId == null ? null : createLotReference(lotId),
unitOfOrderableId == null ? null : createUnitOfOrderableReference(unitOfOrderableId),
stockCard.getLotId() == null ? null : createLotReference(stockCard.getLotId()),
stockCard.getStockOnHand(),
stockCard.getOccurredDate(),
stockCard.getProcessedDate(),
Expand All @@ -135,10 +131,6 @@ private ObjectReferenceDto createLotReference(UUID id) {
return createReference(id, LOTS);
}

private ObjectReferenceDto createUnitOfOrderableReference(UUID id) {
return createReference(id, UNIT_OF_ORDERABLES);
}

private ObjectReferenceDto createReference(UUID id, String resourceName) {
return new ObjectReferenceDto(serviceUrl, resourceName, id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE stock_card_line_items ADD COLUMN unitoforderableid UUID;

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/resources/schemas/canFulfillForMe.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"title": "Lot",
"$ref": "referenceObjectDto.json"
},
"unitOfOrderable": {
"type": "object",
"title": "UnitOfOrderable",
"$ref": "referenceObjectDto.json"
},
"stockOnHand": {
"type": "integer"
},
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/schemas/lineItem.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
"type": "string",
"format": "date"
},
"unitOfOrderableId": {
"type": ["string", "null"],
"description": "Indicates the unit for given orderable."
},
"extraData": {
"type": "object",
"description": "Can be used to save additional data for line item.",
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/schemas/physicalInventoryLineItem.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
"title": "LotId",
"description": "Indicates which lot this physical inventory line item is for."
},
"unitOfOrderableId": {
"type": ["string", "null"],
"title": "UnitOfOrderableId",
"description": "Indicates the unit for given orderable."
},
"stockOnHand": {
"type": ["integer", "null"],
"description": "Indicates previous stock on hand for an orderable."
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/schemas/stockCard.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
"title": "Lot",
"$ref": "lot.json"
},
"unitOfOrderableId": {
"type": ["string", "null"],
"title": "UnitOfOrderableId",
"description": "Indicates the unit for given orderable."
},
"extraData": {
"type": "object",
"title": "extraData"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void shouldCreateLineItemFromStockEvent() {
assertThat(cardLineItem.getOriginEvent().getId(), is(eventId));

assertThat(cardLineItem.getUserId(), is(userId));
assertThat(cardLineItem.getUnitOfOrderableId(), is(unitOfOrderableId));

assertEquals(cardLineItem.getStockAdjustments(), eventLineItemDto.stockAdjustments());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void shouldCreateDtoFromJpaModel() throws Exception {
.quantity(123)
.orderableId(UUID.randomUUID())
.lotId(UUID.randomUUID())
.unitOfOrderableId(UUID.randomUUID())
.stockAdjustments(singletonList(createStockAdjustment()))
.build();

Expand All @@ -46,7 +45,6 @@ public void shouldCreateDtoFromJpaModel() throws Exception {
assertThat(lineItemDto.getQuantity(), is(lineItem.getQuantity()));
assertThat(lineItemDto.getOrderableId(), is(lineItem.getOrderableId()));
assertThat(lineItemDto.getLotId(), is(lineItem.getLotId()));
assertThat(lineItemDto.getUnitOfOrderableId(), is(lineItem.getUnitOfOrderableId()));
assertThat(lineItemDto.getStockAdjustments(), is(lineItem.getStockAdjustments()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void shouldCompareStockCardSummariesWithOneAndTwoFulfillingProducts() {
StockCardSummaryV2Dto stockCardWithTwoFulfillingProducts =
new StockCardSummaryV2DtoDataBuilder()
.withCanFulfillForMe(new HashSet<>(Arrays.asList(
new CanFulfillForMeEntryDto(null, null, null, null, 15, null, null, true),
new CanFulfillForMeEntryDto(null, null, null, 15, null, null, true),
new CanFulfillForMeEntryDto())))
.build();
StockCardSummaryV2Dto stockCardWithOneFulfillingProduct = new StockCardSummaryV2DtoDataBuilder()
Expand All @@ -138,7 +138,7 @@ public void shouldCompareThreeStockCardSummariesTransitively() {
StockCardSummaryV2Dto stockCardWithTwoFulfillingProducts =
new StockCardSummaryV2DtoDataBuilder()
.withCanFulfillForMe(new HashSet<>(Arrays.asList(
new CanFulfillForMeEntryDto(null, null, null, null, 15, null, null, true),
new CanFulfillForMeEntryDto(null, null, null, 15, null, null, true),
new CanFulfillForMeEntryDto())))
.build();
StockCardSummaryV2Dto stockCardWithOneFulfillingProduct = new StockCardSummaryV2DtoDataBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class StockCardServiceTest {

@Mock
private PermissionStrings.Handler permissionStringsHandler;

@Mock
private CalculatedStockOnHandService calculatedStockOnHandService;

Expand Down Expand Up @@ -134,9 +134,7 @@ public void setUp() {
.thenReturn(ProgramDto.builder().id(programId).build());

StockEvent originalEvent = new StockEventDataBuilder()
.withFacility(facilityId)
.withProgram(programId)
.build();
.withFacility(facilityId).withProgram(programId).build();
stockCard = new StockCardDataBuilder(originalEvent).build();

SecurityContextHolder.setContext(securityContext);
Expand Down Expand Up @@ -166,14 +164,9 @@ public void shouldNotDuplicateCardsForOrderableLots() {

assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(0).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(0).getLotId()));
assertThat(card.getUnitOfOrderableId(),
equalTo(event.getLineItems().get(0).getUnitOfOrderableId()));

assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(1).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(1).getLotId()));
assertThat(card.getUnitOfOrderableId(),
equalTo(event.getLineItems().get(1).getUnitOfOrderableId()));

assertThat(card.getLineItems(), hasSize(2));
}

Expand Down
Loading
Loading