Search in sources :

Example 21 with ContractVersion

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);
}
Also used : ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) ContractVersion(com.axelor.apps.contract.db.ContractVersion) Contract(com.axelor.apps.contract.db.Contract)

Example 22 with ContractVersion

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);
    }
}
Also used : PersistenceException(javax.persistence.PersistenceException) ContractVersion(com.axelor.apps.contract.db.ContractVersion) AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException)

Example 23 with ContractVersion

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;
}
Also used : ContractLine(com.axelor.apps.contract.db.ContractLine) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Aggregations

ContractVersion (com.axelor.apps.contract.db.ContractVersion)23 Transactional (com.google.inject.persist.Transactional)12 Contract (com.axelor.apps.contract.db.Contract)9 ContractLine (com.axelor.apps.contract.db.ContractLine)5 ContractVersionRepository (com.axelor.apps.contract.db.repo.ContractVersionRepository)5 Invoice (com.axelor.apps.account.db.Invoice)4 ContractRepository (com.axelor.apps.contract.db.repo.ContractRepository)4 AxelorException (com.axelor.exception.AxelorException)3 Account (com.axelor.apps.account.db.Account)2 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)2 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 TaxLine (com.axelor.apps.account.db.TaxLine)2 AnalyticMoveLineRepository (com.axelor.apps.account.db.repo.AnalyticMoveLineRepository)2 InvoiceLineRepository (com.axelor.apps.account.db.repo.InvoiceLineRepository)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 FiscalPositionAccountService (com.axelor.apps.account.service.FiscalPositionAccountService)2 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)2 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)2 InvoiceServiceImpl (com.axelor.apps.account.service.invoice.InvoiceServiceImpl)2