use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractVersionController method save.
public void save(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;
}
// TODO: move in service
JPA.runInTransaction(() -> {
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 ContractRepository method save.
@Override
public Contract save(Contract contract) {
try {
if (contract.getContractId() == null) {
contract.setContractId(computeSeq(contract.getCompany(), contract.getTargetTypeSelect()));
}
ContractVersion currentContractVersion = contract.getCurrentContractVersion();
currentContractVersion.setIsConsumptionManagement(contract.getIsConsumptionManagement());
return super.save(contract);
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractVersionRepository method copy.
public ContractVersion copy(Contract contract) {
ContractVersion newVersion = new ContractVersion();
ContractVersion currentVersion = contract.getCurrentContractVersion();
newVersion.setStatusSelect(ContractVersionRepository.DRAFT_VERSION);
newVersion.setNextContract(contract);
newVersion.setPaymentMode(currentVersion.getPaymentMode());
newVersion.setPaymentCondition(currentVersion.getPaymentCondition());
newVersion.setInvoicingDuration(currentVersion.getInvoicingDuration());
newVersion.setInvoicingMomentSelect(currentVersion.getInvoicingMomentSelect());
newVersion.setIsPeriodicInvoicing(currentVersion.getIsPeriodicInvoicing());
newVersion.setAutomaticInvoicing(currentVersion.getAutomaticInvoicing());
newVersion.setIsProratedInvoice(currentVersion.getIsProratedInvoice());
newVersion.setIsProratedFirstInvoice(currentVersion.getIsProratedFirstInvoice());
newVersion.setIsProratedLastInvoice(currentVersion.getIsProratedLastInvoice());
newVersion.setDescription(currentVersion.getDescription());
newVersion.setIsTacitRenewal(currentVersion.getIsTacitRenewal());
newVersion.setRenewalDuration(currentVersion.getRenewalDuration());
newVersion.setIsAutoEnableVersionOnRenew(currentVersion.getIsAutoEnableVersionOnRenew());
newVersion.setIsWithEngagement(currentVersion.getIsWithEngagement());
newVersion.setEngagementDuration(currentVersion.getEngagementDuration());
newVersion.setIsWithPriorNotice(currentVersion.getIsWithPriorNotice());
newVersion.setPriorNoticeDuration(currentVersion.getPriorNoticeDuration());
newVersion.setEngagementStartFromVersion(currentVersion.getEngagementStartFromVersion());
newVersion.setDoNotRenew(currentVersion.getDoNotRenew());
ContractLineRepository repository = Beans.get(ContractLineRepository.class);
List<ContractLine> lines = ModelTool.copy(repository, currentVersion.getContractLineList(), false);
newVersion.setContractLineList(lines);
newVersion.setIsTimeProratedInvoice(currentVersion.getIsTimeProratedInvoice());
newVersion.setIsVersionProratedInvoice(currentVersion.getIsVersionProratedInvoice());
newVersion.setIsConsumptionBeforeEndDate(currentVersion.getIsConsumptionBeforeEndDate());
newVersion.setIsConsumptionManagement(currentVersion.getIsConsumptionManagement());
return newVersion;
}
Aggregations