Compare commits
2 Commits
feature/su
...
f369e97915
| 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
|
||||
public QvmOperation createNextOperation(QvmOperation operation, Long userId)
|
||||
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.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 {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(QvmOperationServiceImpl.class);
|
||||
@Inject protected SequenceService sequenceService;
|
||||
|
||||
@Inject
|
||||
private QvmOperationRepository qvmOperationRepo;
|
||||
@Transactional
|
||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException {
|
||||
|
||||
@ -103,9 +113,16 @@ public class QvmOperationServiceImpl implements QvmOperationService {
|
||||
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);
|
||||
if (operation != null) {
|
||||
List<QvmOperation> operations = qvmOperationRepo.all()
|
||||
.filter("self.operationOrigin = :serialNumber")
|
||||
.bind("serialNumber", operation.getSerialNumber())
|
||||
.fetch();
|
||||
int size = operations.size();
|
||||
if (size == 0){
|
||||
log.debug("Creating next operation");
|
||||
try{
|
||||
nextOperation.setStatusSelect(1);
|
||||
nextOperation.setOperationOrigin(operation.getSerialNumber());
|
||||
@ -114,25 +131,51 @@ public class QvmOperationServiceImpl implements QvmOperationService {
|
||||
nextOperation.setOperationDate(operation.getOperationDueDate());
|
||||
if (operation.getOperationFrequency() == 1){
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusYears(1));
|
||||
nextOperation.setCountdown(364);
|
||||
}
|
||||
nextOperation.setCountdown(364);}
|
||||
if (operation.getOperationFrequency() == 2){
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(1));
|
||||
nextOperation.setCountdown(31);
|
||||
}
|
||||
nextOperation.setCountdown(31);}
|
||||
if (operation.getOperationFrequency() == 3){
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(6));
|
||||
nextOperation.setCountdown(183);
|
||||
}
|
||||
System.out.println(
|
||||
"operation.getOperationFrequency : " + operation.getOperationFrequency());
|
||||
nextOperation.setCountdown(183);}
|
||||
nextOperation.setSerialNumber(null);
|
||||
nextOperation.setCreationType(2);
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
catch (Exception exception){
|
||||
log.error("Error while creating next operation");
|
||||
System.out.println(exception);
|
||||
}}else{
|
||||
log.debug("Origin alredy used");
|
||||
throw new AxelorException(
|
||||
TraceBackRepository.CATEGORY_NO_UNIQUE_KEY,
|
||||
I18n.get(IExceptionMessage.ORIGIN_ALREDY_USED),
|
||||
operation.getSerialNumber());
|
||||
}
|
||||
}
|
||||
// Beans.get(QvmOperationRepository.class).save(nextOperation);
|
||||
System.out.println("Create next operation : "+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;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,9 +135,6 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
||||
stockMove, purchaseOrderRepo.find(origin), qtyToInvoiceMap);
|
||||
} else {
|
||||
invoice = createInvoiceFromOrderlessStockMove(stockMove, qtyToInvoiceMap);
|
||||
invoice.setExTaxTotal(stockMove.getExTaxTotal());
|
||||
BigDecimal inTaxTotal = invoice.getExTaxTotal().add(invoice.getExTaxTotal().multiply(invoice.getTaxTotal())).setScale(2, RoundingMode.HALF_UP);
|
||||
invoice.setInTaxTotal(inTaxTotal);
|
||||
}
|
||||
return invoice;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user