use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractVersionController method newDraft.
public void newDraft(ActionRequest request, ActionResponse response) {
Long contractId = Long.valueOf(request.getContext().get("_xContractId").toString());
Contract contract = Beans.get(ContractRepository.class).find(contractId);
ContractVersion newVersion = Beans.get(ContractVersionService.class).newDraft(contract);
response.setValues(Mapper.toMap(newVersion));
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractVersionController method waiting.
public void waiting(ActionRequest request, ActionResponse response) {
try {
Long id = request.getContext().asType(ContractVersion.class).getId();
ContractVersion contractVersion = Beans.get(ContractVersionRepository.class).find(id);
if (contractVersion.getNextContract() == null) {
response.setError(I18n.get(IExceptionMessage.CONTRACT_VERSION_EMPTY_NEXT_CONTRACT));
return;
}
Beans.get(ContractService.class).waitingNextVersion(contractVersion.getNextContract(), getTodayDate(contractVersion.getNextContract().getCompany()));
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractController method saveNextVersion.
public void saveNextVersion(ActionRequest request, ActionResponse response) {
final ContractVersion version = JPA.find(ContractVersion.class, request.getContext().asType(ContractVersion.class).getId());
if (version.getNextContract() != null) {
return;
}
Object xContractId = request.getContext().get("_xContractId");
Long contractId;
if (xContractId != null) {
contractId = Long.valueOf(xContractId.toString());
} else if (version.getContract() != null) {
contractId = version.getContract().getId();
} else {
contractId = null;
}
if (contractId == null) {
return;
}
JPA.runInTransaction(new Runnable() {
@Override
public void run() {
Contract contract = JPA.find(Contract.class, contractId);
contract.setNextVersion(version);
Beans.get(ContractRepository.class).save(contract);
}
});
response.setReload(true);
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractVersionController method changeProduct.
public void changeProduct(ActionRequest request, ActionResponse response) {
ContractLineService contractLineService = Beans.get(ContractLineService.class);
ContractLine contractLine = new ContractLine();
try {
contractLine = request.getContext().asType(ContractLine.class);
ContractVersion contractVersion = request.getContext().getParent().asType(ContractVersion.class);
Contract contract = contractVersion.getNextContract() == null ? contractVersion.getContract() : contractVersion.getNextContract();
Product product = contractLine.getProduct();
contractLine = contractLineService.fillAndCompute(contractLine, contract, product);
response.setValues(contractLine);
} catch (Exception e) {
response.setValues(contractLineService.reset(contractLine));
}
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractServiceImpl method archiveVersion.
@Override
@Transactional
public void archiveVersion(Contract contract, LocalDate date) {
ContractVersion currentVersion = contract.getCurrentContractVersion();
ContractVersion nextVersion = contract.getNextVersion();
contract.addVersionHistory(currentVersion);
currentVersion.setContract(null);
contract.setCurrentContractVersion(nextVersion);
nextVersion.setNextContract(null);
nextVersion.setContract(contract);
contract.setNextVersion(null);
save(contract);
}
Aggregations