Compare commits
2 Commits
feature/co
...
feature/up
| Author | SHA1 | Date | |
|---|---|---|---|
| f369e97915 | |||
| 0a9e03261b |
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Axelor Business Solutions
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.axelor.apps.qvm.exception;
|
||||||
|
|
||||||
|
/** Interface of Exceptions. Enum all exception of axelor-human-resource. */
|
||||||
|
public interface IExceptionMessage {
|
||||||
|
|
||||||
|
static final String ORIGIN_ALREDY_USED = /*$$(*/
|
||||||
|
"origin alredy used : %s" /*)*/;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package com.axelor.apps.qvm.job;
|
||||||
|
|
||||||
|
import com.axelor.exception.service.TraceBackService;
|
||||||
|
import com.axelor.inject.Beans;
|
||||||
|
import java.util.List;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.quartz.SchedulerException;
|
||||||
|
import com.axelor.apps.qvm.service.QvmOperationService;
|
||||||
|
import com.axelor.apps.qvm.service.QvmOperationServiceImpl;
|
||||||
|
public class CalculateCountdownJob implements Job {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(CalculateCountdownJob.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) throws JobExecutionException{
|
||||||
|
|
||||||
|
if (isRunning(context)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
log.debug("Calculating operation countdown ...");
|
||||||
|
Beans.get(QvmOperationServiceImpl.class).updateAllCountdowns();
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("Error while operation countdown");
|
||||||
|
TraceBackService.trace(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isRunning(JobExecutionContext context) {
|
||||||
|
try {
|
||||||
|
return context
|
||||||
|
.getScheduler()
|
||||||
|
.getCurrentlyExecutingJobs()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(
|
||||||
|
j ->
|
||||||
|
j.getTrigger().equals(context.getTrigger())
|
||||||
|
&& !j.getFireInstanceId().equals(context.getFireInstanceId()));
|
||||||
|
} catch (SchedulerException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -39,4 +39,7 @@ public interface QvmOperationService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public QvmOperation createNextOperation(QvmOperation operation, Long userId)
|
public QvmOperation createNextOperation(QvmOperation operation, Long userId)
|
||||||
throws AxelorException;
|
throws AxelorException;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void updateAllCountdowns()throws AxelorException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,10 +29,20 @@ import com.axelor.inject.Beans;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.persist.Transactional;
|
import com.google.inject.persist.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import com.axelor.apps.qvm.exception.IExceptionMessage;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
public class QvmOperationServiceImpl implements QvmOperationService {
|
public class QvmOperationServiceImpl implements QvmOperationService {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(QvmOperationServiceImpl.class);
|
||||||
@Inject protected SequenceService sequenceService;
|
@Inject protected SequenceService sequenceService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private QvmOperationRepository qvmOperationRepo;
|
||||||
@Transactional
|
@Transactional
|
||||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException {
|
public QvmOperation createCalibrationSeq(Company company) throws AxelorException {
|
||||||
|
|
||||||
@ -103,36 +113,69 @@ public class QvmOperationServiceImpl implements QvmOperationService {
|
|||||||
return calibration;
|
return calibration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QvmOperation createNextOperation(QvmOperation operation, Long userId) {
|
public QvmOperation createNextOperation(QvmOperation operation, Long userId) throws AxelorException{
|
||||||
QvmOperation nextOperation = Beans.get(QvmOperationRepository.class).copy(operation, true);
|
QvmOperation nextOperation = Beans.get(QvmOperationRepository.class).copy(operation, true);
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
try {
|
List<QvmOperation> operations = qvmOperationRepo.all()
|
||||||
nextOperation.setStatusSelect(1);
|
.filter("self.operationOrigin = :serialNumber")
|
||||||
nextOperation.setOperationOrigin(operation.getSerialNumber());
|
.bind("serialNumber", operation.getSerialNumber())
|
||||||
nextOperation.setCreationType(2);
|
.fetch();
|
||||||
nextOperation.setPastOperationDate(operation.getOperationDate());
|
int size = operations.size();
|
||||||
nextOperation.setOperationDate(operation.getOperationDueDate());
|
if (size == 0){
|
||||||
if (operation.getOperationFrequency() == 1) {
|
log.debug("Creating next operation");
|
||||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusYears(1));
|
try{
|
||||||
nextOperation.setCountdown(364);
|
nextOperation.setStatusSelect(1);
|
||||||
|
nextOperation.setOperationOrigin(operation.getSerialNumber());
|
||||||
|
nextOperation.setCreationType(2);
|
||||||
|
nextOperation.setPastOperationDate(operation.getOperationDate());
|
||||||
|
nextOperation.setOperationDate(operation.getOperationDueDate());
|
||||||
|
if (operation.getOperationFrequency() == 1){
|
||||||
|
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusYears(1));
|
||||||
|
nextOperation.setCountdown(364);}
|
||||||
|
if (operation.getOperationFrequency() == 2){
|
||||||
|
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(1));
|
||||||
|
nextOperation.setCountdown(31);}
|
||||||
|
if (operation.getOperationFrequency() == 3){
|
||||||
|
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(6));
|
||||||
|
nextOperation.setCountdown(183);}
|
||||||
|
nextOperation.setSerialNumber(null);
|
||||||
|
nextOperation.setCreationType(2);
|
||||||
}
|
}
|
||||||
if (operation.getOperationFrequency() == 2) {
|
catch (Exception exception){
|
||||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(1));
|
log.error("Error while creating next operation");
|
||||||
nextOperation.setCountdown(31);
|
System.out.println(exception);
|
||||||
}
|
}}else{
|
||||||
if (operation.getOperationFrequency() == 3) {
|
log.debug("Origin alredy used");
|
||||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(6));
|
throw new AxelorException(
|
||||||
nextOperation.setCountdown(183);
|
TraceBackRepository.CATEGORY_NO_UNIQUE_KEY,
|
||||||
}
|
I18n.get(IExceptionMessage.ORIGIN_ALREDY_USED),
|
||||||
System.out.println(
|
operation.getSerialNumber());
|
||||||
"operation.getOperationFrequency : " + operation.getOperationFrequency());
|
|
||||||
nextOperation.setSerialNumber(null);
|
|
||||||
nextOperation.setCreationType(2);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
System.out.println(exception);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Beans.get(QvmOperationRepository.class).save(nextOperation);
|
System.out.println("Create next operation : "+nextOperation);
|
||||||
return nextOperation;
|
return nextOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void updateCountdown(QvmOperation operation, LocalDate today) {
|
||||||
|
if (operation.getOperationDate() != null) {
|
||||||
|
|
||||||
|
LocalDate operationDate = operation.getOperationDate();
|
||||||
|
int daysBetween = (int) ChronoUnit.DAYS.between(today, operationDate);
|
||||||
|
operation.setCountdown(daysBetween);
|
||||||
|
qvmOperationRepo.save(operation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAllCountdowns() {
|
||||||
|
List<QvmOperation> operations = qvmOperationRepo.all()
|
||||||
|
.filter("self.operationDate IS NOT NULL AND self.statusSelect = :status")
|
||||||
|
.bind("status", 2)
|
||||||
|
.fetch();
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
for (QvmOperation operation : operations){
|
||||||
|
System.out.println("operation : "+operation);
|
||||||
|
updateCountdown(operation,today);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -165,4 +165,14 @@ public class QvmOperationController {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCountdowns(ActionRequest request, ActionResponse response) {
|
||||||
|
try {
|
||||||
|
Beans.get(QvmOperationService.class).updateAllCountdowns();
|
||||||
|
} catch (AxelorException e) {
|
||||||
|
TraceBackService.trace(e);
|
||||||
|
response.setError(e.getMessage());
|
||||||
|
}
|
||||||
|
response.setFlash("Countdowns updated successfully");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import com.axelor.apps.stock.db.TrackingNumber;
|
|||||||
import com.axelor.apps.stock.db.repo.InventoryLineRepository;
|
import com.axelor.apps.stock.db.repo.InventoryLineRepository;
|
||||||
import com.axelor.apps.stock.db.repo.TrackingNumberRepository;
|
import com.axelor.apps.stock.db.repo.TrackingNumberRepository;
|
||||||
import com.axelor.auth.AuthUtils;
|
import com.axelor.auth.AuthUtils;
|
||||||
import com.axelor.auth.db.User;
|
|
||||||
import com.axelor.db.Query;
|
import com.axelor.db.Query;
|
||||||
import com.axelor.inject.Beans;
|
import com.axelor.inject.Beans;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@ -35,17 +34,12 @@ import com.google.inject.persist.Transactional;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class InventoryLineService {
|
public class InventoryLineService {
|
||||||
|
|
||||||
@Inject private ProductRepository productRepository;
|
@Inject private ProductRepository productRepository;
|
||||||
private TrackingNumberRepository trackingNumberRepository;
|
private TrackingNumberRepository trackingNumberRepository;
|
||||||
@Inject private InventoryLineRepository inventoryLineRepository;
|
private InventoryLineRepository inventoryLineRepository;
|
||||||
|
|
||||||
public InventoryLine createInventoryLine(
|
public InventoryLine createInventoryLine(
|
||||||
Inventory inventory,
|
Inventory inventory,
|
||||||
@ -177,370 +171,4 @@ public class InventoryLineService {
|
|||||||
|
|
||||||
Beans.get(InventoryLineRepository.class).save(line);
|
Beans.get(InventoryLineRepository.class).save(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void consolidateInventoryLines(StockLocation stockLocation, Boolean addInternalTrackingNumber) {
|
|
||||||
|
|
||||||
List<InventoryLine> inventoryLines =
|
|
||||||
inventoryLineRepository
|
|
||||||
.all()
|
|
||||||
.filter(
|
|
||||||
"self.stockLocation = ?1 " +
|
|
||||||
//"AND (self.isConsolidate = false OR self.isConsolidate is null) " +
|
|
||||||
"AND (self.archived = false OR self.archived is null)",
|
|
||||||
stockLocation
|
|
||||||
)
|
|
||||||
.fetch();
|
|
||||||
|
|
||||||
System.out.println("************* lines" + inventoryLines);
|
|
||||||
Map<String, List<InventoryLine>> groupedLines =
|
|
||||||
inventoryLines.stream()
|
|
||||||
.filter(line -> line.getProductName() != null)
|
|
||||||
.filter(line ->
|
|
||||||
!addInternalTrackingNumber ||
|
|
||||||
line.getInternalTrackingNumberStr() == null
|
|
||||||
)
|
|
||||||
.collect(Collectors.groupingBy(line -> {
|
|
||||||
|
|
||||||
String key =
|
|
||||||
line.getStockLocation().getId() + "|" +
|
|
||||||
(line.getProduct() != null
|
|
||||||
? line.getProduct().getId()
|
|
||||||
: line.getProductName().trim().toUpperCase()) + "|" +
|
|
||||||
(line.getUnit() != null ? line.getUnit().getId() : "NULL") + "|" +
|
|
||||||
(line.getTrackingNumber() != null
|
|
||||||
? line.getTrackingNumber().getId()
|
|
||||||
: "NULL") + "|" +
|
|
||||||
(line.getTrackingNumberStr() != null
|
|
||||||
? line.getTrackingNumberStr().trim().toUpperCase()
|
|
||||||
: "NULL");
|
|
||||||
|
|
||||||
if (addInternalTrackingNumber) {
|
|
||||||
key += "|" +
|
|
||||||
(line.getInternalTrackingNumberStr() != null
|
|
||||||
? line.getInternalTrackingNumberStr().trim().toUpperCase()
|
|
||||||
: "NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}));
|
|
||||||
|
|
||||||
List<InventoryLine> consolidatedInventoryLines = new ArrayList<>();
|
|
||||||
System.out.println("************* lines" + groupedLines);
|
|
||||||
for (List<InventoryLine> lines : groupedLines.values()) {
|
|
||||||
|
|
||||||
if (lines.size() <= 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryLine consolidated1 = lines.stream()
|
|
||||||
.filter(InventoryLine::getIsConsolidate)
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
boolean hasConsolidatedLine = consolidated1 != null;
|
|
||||||
|
|
||||||
|
|
||||||
if(!hasConsolidatedLine){
|
|
||||||
|
|
||||||
InventoryLine first = lines.get(0);
|
|
||||||
|
|
||||||
BigDecimal firstCounting = BigDecimal.ZERO;
|
|
||||||
User firstCountingByUser = null;
|
|
||||||
LocalDateTime firstCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal secondCounting = BigDecimal.ZERO;
|
|
||||||
User secondCountingByUser = null;
|
|
||||||
LocalDateTime secondCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal thirdCounting = BigDecimal.ZERO;
|
|
||||||
User thirdCountingByUser = null;
|
|
||||||
LocalDateTime thirdCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal forthCounting = BigDecimal.ZERO;
|
|
||||||
User forthCountingByUser = null;
|
|
||||||
LocalDateTime forthCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal controlCounting = BigDecimal.ZERO;
|
|
||||||
User controlCountingByUser = null;
|
|
||||||
LocalDateTime controlCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal fifthCounting = BigDecimal.ZERO;
|
|
||||||
User fifthCountingByUser = null;
|
|
||||||
LocalDateTime fifthCountingDate = null;
|
|
||||||
|
|
||||||
BigDecimal sixthCounting = BigDecimal.ZERO;
|
|
||||||
User sixthCountingByUser = null;
|
|
||||||
LocalDateTime sixthCountingDate = null;
|
|
||||||
|
|
||||||
for (InventoryLine line : lines) {
|
|
||||||
if (line.getFirstCounting() != null) {
|
|
||||||
firstCounting = firstCounting.add(line.getFirstCounting());
|
|
||||||
if (firstCountingByUser == null) {
|
|
||||||
firstCountingByUser = line.getFirstCountingByUser();
|
|
||||||
firstCountingDate = line.getFirstCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getSecondCounting() != null) {
|
|
||||||
secondCounting = secondCounting.add(line.getSecondCounting());
|
|
||||||
if (secondCountingByUser == null) {
|
|
||||||
secondCountingByUser = line.getSecondCountingByUser();
|
|
||||||
secondCountingDate = line.getSecondCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getThirdCounting() != null) {
|
|
||||||
thirdCounting = thirdCounting.add(line.getThirdCounting());
|
|
||||||
if (thirdCountingByUser == null) {
|
|
||||||
thirdCountingByUser = line.getThirdCountingByUser();
|
|
||||||
thirdCountingDate = line.getThirdCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getForthCounting() != null) {
|
|
||||||
forthCounting = forthCounting.add(line.getForthCounting());
|
|
||||||
if (forthCountingByUser == null) {
|
|
||||||
forthCountingByUser = line.getForthCountingByUser();
|
|
||||||
forthCountingDate = line.getForthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getControlCounting() != null) {
|
|
||||||
controlCounting = controlCounting.add(line.getControlCounting());
|
|
||||||
if (controlCountingByUser == null) {
|
|
||||||
controlCountingByUser = line.getControlCountingByUser();
|
|
||||||
controlCountingDate = line.getControlCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getFifthCounting() != null) {
|
|
||||||
fifthCounting = fifthCounting.add(line.getFifthCounting());
|
|
||||||
if (fifthCountingByUser == null) {
|
|
||||||
fifthCountingByUser = line.getFifthCountingByUser();
|
|
||||||
fifthCountingDate = line.getFifthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getSixthCounting() != null) {
|
|
||||||
sixthCounting = sixthCounting.add(line.getSixthCounting());
|
|
||||||
if (sixthCountingByUser == null) {
|
|
||||||
sixthCountingByUser = line.getSixthCountingByUser();
|
|
||||||
sixthCountingDate = line.getSixthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryLine consolidated = new InventoryLine();
|
|
||||||
consolidated.setStockLocation(first.getStockLocation());
|
|
||||||
if(first.getProduct() != null)
|
|
||||||
consolidated.setProduct(first.getProduct());
|
|
||||||
consolidated.setProductName(first.getProductName().trim().toUpperCase());
|
|
||||||
if(first.getUnit() != null)
|
|
||||||
consolidated.setUnit(first.getUnit());
|
|
||||||
if (first.getTrackingNumber() != null) {
|
|
||||||
consolidated.setTrackingNumber(first.getTrackingNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first.getTrackingNumberStr() != null) {
|
|
||||||
consolidated.setTrackingNumberStr(first.getTrackingNumberStr().trim().toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addInternalTrackingNumber && first.getInternalTrackingNumberStr() != null)
|
|
||||||
consolidated.setInternalTrackingNumberStr(first.getInternalTrackingNumberStr().trim().toUpperCase());
|
|
||||||
|
|
||||||
consolidated.setFirstCounting(firstCounting);
|
|
||||||
consolidated.setFirstCountingByUser(firstCountingByUser);
|
|
||||||
consolidated.setFirstCountingDate(firstCountingDate);
|
|
||||||
|
|
||||||
consolidated.setSecondCounting(secondCounting);
|
|
||||||
consolidated.setSecondCountingByUser(secondCountingByUser);
|
|
||||||
consolidated.setSecondCountingDate(secondCountingDate);
|
|
||||||
|
|
||||||
consolidated.setThirdCounting(thirdCounting);
|
|
||||||
consolidated.setThirdCountingByUser(thirdCountingByUser);
|
|
||||||
consolidated.setThirdCountingDate(thirdCountingDate);
|
|
||||||
|
|
||||||
consolidated.setForthCounting(forthCounting);
|
|
||||||
consolidated.setForthCountingByUser(forthCountingByUser);
|
|
||||||
consolidated.setForthCountingDate(forthCountingDate);
|
|
||||||
|
|
||||||
consolidated.setControlCounting(controlCounting);
|
|
||||||
consolidated.setControlCountingByUser(controlCountingByUser);
|
|
||||||
consolidated.setControlCountingDate(controlCountingDate);
|
|
||||||
|
|
||||||
consolidated.setFifthCounting(fifthCounting);
|
|
||||||
consolidated.setFifthCountingByUser(fifthCountingByUser);
|
|
||||||
consolidated.setFifthCountingDate(fifthCountingDate);
|
|
||||||
|
|
||||||
consolidated.setSixthCounting(sixthCounting);
|
|
||||||
consolidated.setSixthCountingByUser(sixthCountingByUser);
|
|
||||||
consolidated.setSixthCountingDate(sixthCountingDate);
|
|
||||||
|
|
||||||
|
|
||||||
consolidated.setIsConsolidate(true);
|
|
||||||
|
|
||||||
inventoryLineRepository.save(consolidated);
|
|
||||||
|
|
||||||
// Archive old lines
|
|
||||||
for (InventoryLine line : lines) {
|
|
||||||
line.setArchived(true);
|
|
||||||
inventoryLineRepository.save(line);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
InventoryLine consolidated = consolidated1;
|
|
||||||
|
|
||||||
BigDecimal firstCounting =
|
|
||||||
consolidated.getFirstCounting() != null
|
|
||||||
? consolidated.getFirstCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal secondCounting =
|
|
||||||
consolidated.getSecondCounting() != null
|
|
||||||
? consolidated.getSecondCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal thirdCounting =
|
|
||||||
consolidated.getThirdCounting() != null
|
|
||||||
? consolidated.getThirdCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal forthCounting =
|
|
||||||
consolidated.getForthCounting() != null
|
|
||||||
? consolidated.getForthCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal controlCounting =
|
|
||||||
consolidated.getControlCounting() != null
|
|
||||||
? consolidated.getControlCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal fifthCounting =
|
|
||||||
consolidated.getFifthCounting() != null
|
|
||||||
? consolidated.getFifthCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal sixthCounting =
|
|
||||||
consolidated.getSixthCounting() != null
|
|
||||||
? consolidated.getSixthCounting()
|
|
||||||
: BigDecimal.ZERO;
|
|
||||||
|
|
||||||
User firstCountingByUser = consolidated.getFirstCountingByUser();
|
|
||||||
LocalDateTime firstCountingDate = consolidated.getFirstCountingDate();
|
|
||||||
|
|
||||||
User secondCountingByUser = consolidated.getSecondCountingByUser();
|
|
||||||
LocalDateTime secondCountingDate = consolidated.getSecondCountingDate();
|
|
||||||
|
|
||||||
User thirdCountingByUser = consolidated.getThirdCountingByUser();
|
|
||||||
LocalDateTime thirdCountingDate = consolidated.getThirdCountingDate();
|
|
||||||
|
|
||||||
User forthCountingByUser = consolidated.getForthCountingByUser();
|
|
||||||
LocalDateTime forthCountingDate = consolidated.getForthCountingDate();
|
|
||||||
|
|
||||||
User controlCountingByUser = consolidated.getControlCountingByUser();
|
|
||||||
LocalDateTime controlCountingDate = consolidated.getControlCountingDate();
|
|
||||||
|
|
||||||
User fifthCountingByUser = consolidated.getFifthCountingByUser();
|
|
||||||
LocalDateTime fifthCountingDate = consolidated.getFifthCountingDate();
|
|
||||||
|
|
||||||
User sixthCountingByUser = consolidated.getSixthCountingByUser();
|
|
||||||
LocalDateTime sixthCountingDate = consolidated.getSixthCountingDate();
|
|
||||||
|
|
||||||
for (InventoryLine line : lines) {
|
|
||||||
|
|
||||||
if (line.getIsConsolidate()) {
|
|
||||||
continue; // skip the consolidated line itself
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getFirstCounting() != null) {
|
|
||||||
firstCounting = firstCounting.add(line.getFirstCounting());
|
|
||||||
if (firstCountingByUser == null) {
|
|
||||||
firstCountingByUser = line.getFirstCountingByUser();
|
|
||||||
firstCountingDate = line.getFirstCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getSecondCounting() != null) {
|
|
||||||
secondCounting = secondCounting.add(line.getSecondCounting());
|
|
||||||
if (secondCountingByUser == null) {
|
|
||||||
secondCountingByUser = line.getSecondCountingByUser();
|
|
||||||
secondCountingDate = line.getSecondCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getThirdCounting() != null) {
|
|
||||||
thirdCounting = thirdCounting.add(line.getThirdCounting());
|
|
||||||
if (thirdCountingByUser == null) {
|
|
||||||
thirdCountingByUser = line.getThirdCountingByUser();
|
|
||||||
thirdCountingDate = line.getThirdCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getForthCounting() != null) {
|
|
||||||
forthCounting = forthCounting.add(line.getForthCounting());
|
|
||||||
if (forthCountingByUser == null) {
|
|
||||||
forthCountingByUser = line.getForthCountingByUser();
|
|
||||||
forthCountingDate = line.getForthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getControlCounting() != null) {
|
|
||||||
controlCounting = controlCounting.add(line.getControlCounting());
|
|
||||||
if (controlCountingByUser == null) {
|
|
||||||
controlCountingByUser = line.getControlCountingByUser();
|
|
||||||
controlCountingDate = line.getControlCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getFifthCounting() != null) {
|
|
||||||
fifthCounting = fifthCounting.add(line.getFifthCounting());
|
|
||||||
if (fifthCountingByUser == null) {
|
|
||||||
fifthCountingByUser = line.getFifthCountingByUser();
|
|
||||||
fifthCountingDate = line.getFifthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.getSixthCounting() != null) {
|
|
||||||
sixthCounting = sixthCounting.add(line.getSixthCounting());
|
|
||||||
if (sixthCountingByUser == null) {
|
|
||||||
sixthCountingByUser = line.getSixthCountingByUser();
|
|
||||||
sixthCountingDate = line.getSixthCountingDate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
line.setArchived(true);
|
|
||||||
inventoryLineRepository.save(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
consolidated.setFirstCounting(firstCounting);
|
|
||||||
consolidated.setFirstCountingByUser(firstCountingByUser);
|
|
||||||
consolidated.setFirstCountingDate(firstCountingDate);
|
|
||||||
|
|
||||||
consolidated.setSecondCounting(secondCounting);
|
|
||||||
consolidated.setSecondCountingByUser(secondCountingByUser);
|
|
||||||
consolidated.setSecondCountingDate(secondCountingDate);
|
|
||||||
|
|
||||||
consolidated.setThirdCounting(thirdCounting);
|
|
||||||
consolidated.setThirdCountingByUser(thirdCountingByUser);
|
|
||||||
consolidated.setThirdCountingDate(thirdCountingDate);
|
|
||||||
|
|
||||||
consolidated.setForthCounting(forthCounting);
|
|
||||||
consolidated.setForthCountingByUser(forthCountingByUser);
|
|
||||||
consolidated.setForthCountingDate(forthCountingDate);
|
|
||||||
|
|
||||||
consolidated.setControlCounting(controlCounting);
|
|
||||||
consolidated.setControlCountingByUser(controlCountingByUser);
|
|
||||||
consolidated.setControlCountingDate(controlCountingDate);
|
|
||||||
|
|
||||||
consolidated.setFifthCounting(fifthCounting);
|
|
||||||
consolidated.setFifthCountingByUser(fifthCountingByUser);
|
|
||||||
consolidated.setFifthCountingDate(fifthCountingDate);
|
|
||||||
|
|
||||||
consolidated.setSixthCounting(sixthCounting);
|
|
||||||
consolidated.setSixthCountingByUser(sixthCountingByUser);
|
|
||||||
consolidated.setSixthCountingDate(sixthCountingDate);
|
|
||||||
inventoryLineRepository.save(consolidated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,9 @@ import com.axelor.apps.base.db.repo.ProductRepository;
|
|||||||
import com.axelor.apps.stock.db.Inventory;
|
import com.axelor.apps.stock.db.Inventory;
|
||||||
import com.axelor.apps.stock.db.InventoryLine;
|
import com.axelor.apps.stock.db.InventoryLine;
|
||||||
import com.axelor.apps.stock.db.StockLocationLine;
|
import com.axelor.apps.stock.db.StockLocationLine;
|
||||||
import com.axelor.apps.stock.db.StockLocation;
|
|
||||||
import com.axelor.apps.stock.db.TrackingNumber;
|
import com.axelor.apps.stock.db.TrackingNumber;
|
||||||
import com.axelor.apps.stock.db.repo.InventoryLineRepository;
|
import com.axelor.apps.stock.db.repo.InventoryLineRepository;
|
||||||
import com.axelor.apps.stock.db.repo.InventoryRepository;
|
import com.axelor.apps.stock.db.repo.InventoryRepository;
|
||||||
import com.axelor.apps.stock.db.repo.StockLocationRepository;
|
|
||||||
import com.axelor.apps.stock.db.repo.TrackingNumberRepository;
|
import com.axelor.apps.stock.db.repo.TrackingNumberRepository;
|
||||||
import com.axelor.apps.stock.service.InventoryLineService;
|
import com.axelor.apps.stock.service.InventoryLineService;
|
||||||
import com.axelor.exception.AxelorException;
|
import com.axelor.exception.AxelorException;
|
||||||
@ -40,7 +38,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class InventoryLineController {
|
public class InventoryLineController {
|
||||||
@ -224,29 +221,4 @@ public class InventoryLineController {
|
|||||||
response.setFlash("Updated Successfully");
|
response.setFlash("Updated Successfully");
|
||||||
// response.setReload(true);
|
// response.setReload(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void consolidateInventoryLines(ActionRequest request, ActionResponse response){
|
|
||||||
|
|
||||||
Object object = request.getContext().get("stockLocation");
|
|
||||||
LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) object;
|
|
||||||
Integer stockLocationIdInt = (Integer) stockLocationMap.get("id");
|
|
||||||
Long stockLocationId = stockLocationIdInt.longValue();
|
|
||||||
StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(stockLocationId);
|
|
||||||
|
|
||||||
Beans.get(InventoryLineService.class).consolidateInventoryLines(stockLocation,false);
|
|
||||||
response.setFlash("Updated Successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void consolidateInventoryLinesWithInternalTrackingNumber(ActionRequest request, ActionResponse response){
|
|
||||||
|
|
||||||
|
|
||||||
Object object = request.getContext().get("stockLocation");
|
|
||||||
LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) object;
|
|
||||||
Integer stockLocationIdInt = (Integer) stockLocationMap.get("id");
|
|
||||||
Long stockLocationId = stockLocationIdInt.longValue();
|
|
||||||
StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(stockLocationId);
|
|
||||||
|
|
||||||
Beans.get(InventoryLineService.class).consolidateInventoryLines(stockLocation,true);
|
|
||||||
response.setFlash("Updated Successfully");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,6 @@
|
|||||||
|
|
||||||
<integer name="conformitySelect" title="Conformity" selection="stock.move.line.conformity.select"/>
|
<integer name="conformitySelect" title="Conformity" selection="stock.move.line.conformity.select"/>
|
||||||
<integer name="stateSelect" title="State" selection="inventory.line.state.select"/>
|
<integer name="stateSelect" title="State" selection="inventory.line.state.select"/>
|
||||||
<boolean name="isConsolidate" title="is Consolidate"/>
|
|
||||||
|
|
||||||
|
|
||||||
<track>
|
<track>
|
||||||
|
|||||||
Reference in New Issue
Block a user