Search in sources :

Example 1 with ContractVersion

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

Example 2 with ContractVersion

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

Example 3 with ContractVersion

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

Example 4 with ContractVersion

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

Example 5 with ContractVersion

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

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