|
|
|
|
@ -10,15 +10,20 @@ import cn.iocoder.yudao.module.erp.controller.admin.bitwms.vo.BitWmsLabelRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.bitwms.vo.BitWmsMoveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.bitwms.vo.BitWmsOutboundReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInAuditReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move.ErpStockMoveSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutAuditReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.warehouselocation.WarehouseLocationMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.warehouselocation.WarehouseLocationDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockMoveService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
|
@ -29,6 +34,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PRODUCT_UNIT_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_COUNT_NEGATIVE2;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
|
@ -54,6 +60,8 @@ class BitWmsServiceImplTest {
|
|
|
|
|
@Mock
|
|
|
|
|
private ErpStockInService stockInService;
|
|
|
|
|
@Mock
|
|
|
|
|
private ErpStockOutService stockOutService;
|
|
|
|
|
@Mock
|
|
|
|
|
private ErpStockMoveService stockMoveService;
|
|
|
|
|
@Mock
|
|
|
|
|
private ErpStockService stockService;
|
|
|
|
|
@ -69,6 +77,7 @@ class BitWmsServiceImplTest {
|
|
|
|
|
reqVO.setWarehouseId(20L);
|
|
|
|
|
reqVO.setAreaId(30L);
|
|
|
|
|
reqVO.setCount(new BigDecimal("2"));
|
|
|
|
|
reqVO.setUnitId(5L);
|
|
|
|
|
reqVO.setRemark("first shelf");
|
|
|
|
|
|
|
|
|
|
ErpProductRespVO product = buildBitSampleProduct();
|
|
|
|
|
@ -87,6 +96,74 @@ class BitWmsServiceImplTest {
|
|
|
|
|
assertEquals(20L, stockIn.getItems().get(0).getWarehouseId());
|
|
|
|
|
assertEquals(30L, stockIn.getItems().get(0).getAreaId());
|
|
|
|
|
assertEquals(new BigDecimal("2"), stockIn.getItems().get(0).getCount());
|
|
|
|
|
assertEquals(false, stockIn.getItems().get(0).getRelateTask());
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<ErpStockInAuditReqVO> auditCaptor = ArgumentCaptor.forClass(ErpStockInAuditReqVO.class);
|
|
|
|
|
verify(stockInService).auditStockIn(auditCaptor.capture());
|
|
|
|
|
assertEquals(100L, auditCaptor.getValue().getId());
|
|
|
|
|
assertEquals(ErpAuditStatus.APPROVE.getStatus(), auditCaptor.getValue().getStatus());
|
|
|
|
|
assertEquals("first shelf", auditCaptor.getValue().getRemark());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void inbound_whenLocationSelected_usesLocationWarehouseAndArea() {
|
|
|
|
|
BitWmsInboundReqVO reqVO = new BitWmsInboundReqVO();
|
|
|
|
|
reqVO.setProductId(10L);
|
|
|
|
|
reqVO.setWarehouseId(999L);
|
|
|
|
|
reqVO.setAreaId(998L);
|
|
|
|
|
reqVO.setLocationId(88L);
|
|
|
|
|
reqVO.setCount(new BigDecimal("2"));
|
|
|
|
|
reqVO.setUnitId(5L);
|
|
|
|
|
|
|
|
|
|
when(productService.getProduct(10L)).thenReturn(buildBitSampleProduct());
|
|
|
|
|
when(warehouseLocationMapper.selectById(88L)).thenReturn(new WarehouseLocationDO()
|
|
|
|
|
.setId(88L).setWarehouseId(20L).setAreaId(30L));
|
|
|
|
|
when(stockInService.createStockIn(org.mockito.ArgumentMatchers.any(ErpStockInSaveReqVO.class))).thenReturn(100L);
|
|
|
|
|
|
|
|
|
|
bitWmsService.inbound(reqVO);
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<ErpStockInSaveReqVO> captor = ArgumentCaptor.forClass(ErpStockInSaveReqVO.class);
|
|
|
|
|
verify(stockInService).createStockIn(captor.capture());
|
|
|
|
|
ErpStockInSaveReqVO stockIn = captor.getValue();
|
|
|
|
|
assertEquals(20L, stockIn.getWarehouseId());
|
|
|
|
|
assertEquals(20L, stockIn.getItems().get(0).getWarehouseId());
|
|
|
|
|
assertEquals(30L, stockIn.getItems().get(0).getAreaId());
|
|
|
|
|
assertEquals(false, stockIn.getItems().get(0).getRelateTask());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void inbound_whenRemarkBlank_autoApprovesWithDefaultRemark() {
|
|
|
|
|
BitWmsInboundReqVO reqVO = new BitWmsInboundReqVO();
|
|
|
|
|
reqVO.setProductId(10L);
|
|
|
|
|
reqVO.setWarehouseId(20L);
|
|
|
|
|
reqVO.setAreaId(30L);
|
|
|
|
|
reqVO.setCount(new BigDecimal("2"));
|
|
|
|
|
reqVO.setUnitId(5L);
|
|
|
|
|
|
|
|
|
|
when(productService.getProduct(10L)).thenReturn(buildBitSampleProduct());
|
|
|
|
|
when(stockInService.createStockIn(org.mockito.ArgumentMatchers.any(ErpStockInSaveReqVO.class))).thenReturn(100L);
|
|
|
|
|
|
|
|
|
|
bitWmsService.inbound(reqVO);
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<ErpStockInAuditReqVO> auditCaptor = ArgumentCaptor.forClass(ErpStockInAuditReqVO.class);
|
|
|
|
|
verify(stockInService).auditStockIn(auditCaptor.capture());
|
|
|
|
|
assertEquals(100L, auditCaptor.getValue().getId());
|
|
|
|
|
assertEquals(ErpAuditStatus.APPROVE.getStatus(), auditCaptor.getValue().getStatus());
|
|
|
|
|
assertEquals("样品入库自动入库", auditCaptor.getValue().getRemark());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void inbound_whenUnitDoesNotMatchSampleUnit_throwsException() {
|
|
|
|
|
BitWmsInboundReqVO reqVO = new BitWmsInboundReqVO();
|
|
|
|
|
reqVO.setProductId(10L);
|
|
|
|
|
reqVO.setWarehouseId(20L);
|
|
|
|
|
reqVO.setAreaId(30L);
|
|
|
|
|
reqVO.setCount(new BigDecimal("2"));
|
|
|
|
|
reqVO.setUnitId(99L);
|
|
|
|
|
|
|
|
|
|
when(productService.getProduct(10L)).thenReturn(buildBitSampleProduct());
|
|
|
|
|
|
|
|
|
|
AssertUtils.assertServiceException(() -> bitWmsService.inbound(reqVO), PRODUCT_UNIT_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ -104,6 +181,41 @@ class BitWmsServiceImplTest {
|
|
|
|
|
AssertUtils.assertServiceException(() -> bitWmsService.outbound(reqVO), STOCK_COUNT_NEGATIVE2, 10L, 20L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void outbound_createsSampleStockOutAndAutoApproves() {
|
|
|
|
|
BitWmsOutboundReqVO reqVO = new BitWmsOutboundReqVO();
|
|
|
|
|
reqVO.setProductId(10L);
|
|
|
|
|
reqVO.setWarehouseId(20L);
|
|
|
|
|
reqVO.setAreaId(30L);
|
|
|
|
|
reqVO.setCount(new BigDecimal("1"));
|
|
|
|
|
reqVO.setOutReason("TEST");
|
|
|
|
|
reqVO.setRemark("out remark");
|
|
|
|
|
|
|
|
|
|
when(productService.getProduct(10L)).thenReturn(buildBitSampleProduct());
|
|
|
|
|
when(stockService.getStock(10L, 20L, 30L)).thenReturn(new ErpStockDO().setCount(new BigDecimal("2")));
|
|
|
|
|
when(stockOutService.createStockOut(org.mockito.ArgumentMatchers.any(ErpStockOutSaveReqVO.class))).thenReturn(200L);
|
|
|
|
|
|
|
|
|
|
Long id = bitWmsService.outbound(reqVO);
|
|
|
|
|
|
|
|
|
|
assertEquals(200L, id);
|
|
|
|
|
ArgumentCaptor<ErpStockOutSaveReqVO> stockOutCaptor = ArgumentCaptor.forClass(ErpStockOutSaveReqVO.class);
|
|
|
|
|
verify(stockOutService).createStockOut(stockOutCaptor.capture());
|
|
|
|
|
ErpStockOutSaveReqVO stockOut = stockOutCaptor.getValue();
|
|
|
|
|
assertEquals("样品出库", stockOut.getOutType());
|
|
|
|
|
assertEquals("出库原因:TEST;out remark", stockOut.getRemark());
|
|
|
|
|
assertEquals(1, stockOut.getItems().size());
|
|
|
|
|
assertEquals(10L, stockOut.getItems().get(0).getProductId());
|
|
|
|
|
assertEquals(20L, stockOut.getItems().get(0).getWarehouseId());
|
|
|
|
|
assertEquals(30L, stockOut.getItems().get(0).getAreaId());
|
|
|
|
|
assertEquals(new BigDecimal("1"), stockOut.getItems().get(0).getCount());
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<ErpStockOutAuditReqVO> auditCaptor = ArgumentCaptor.forClass(ErpStockOutAuditReqVO.class);
|
|
|
|
|
verify(stockOutService).auditStockOut(auditCaptor.capture());
|
|
|
|
|
assertEquals(200L, auditCaptor.getValue().getId());
|
|
|
|
|
assertEquals(ErpAuditStatus.APPROVE.getStatus(), auditCaptor.getValue().getStatus());
|
|
|
|
|
assertEquals("out remark", auditCaptor.getValue().getRemark());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void move_keepsTotalStockAndChangesLocation() {
|
|
|
|
|
BitWmsMoveReqVO reqVO = new BitWmsMoveReqVO();
|
|
|
|
|
@ -191,6 +303,8 @@ class BitWmsServiceImplTest {
|
|
|
|
|
product.setIsSample(true);
|
|
|
|
|
product.setBizUnit("BIT");
|
|
|
|
|
product.setCategoryId(50L);
|
|
|
|
|
product.setUnitId(5L);
|
|
|
|
|
product.setUnitName("个");
|
|
|
|
|
return product;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|