Search in sources :

Example 1 with ContractLine

use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.

the class ContractController 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);
        Contract contract = request.getContext().getParent().asType(Contract.class);
        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) Contract(com.axelor.apps.contract.db.Contract)

Example 2 with ContractLine

use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.

the class ContractLineController method createAnalyticDistributionWithTemplate.

public void createAnalyticDistributionWithTemplate(ActionRequest request, ActionResponse response) {
    ContractLine contractLine = request.getContext().asType(ContractLine.class);
    Context parentContext = request.getContext().getParent();
    Contract contract = null;
    if (parentContext.get("_model").equals(Contract.class.getCanonicalName())) {
        contract = parentContext.asType(Contract.class);
    } else if (parentContext.getParent() != null && parentContext.getParent().get("_model").equals(Contract.class.getCanonicalName())) {
        contract = parentContext.getParent().asType(Contract.class);
    }
    contractLine = Beans.get(ContractLineService.class).createAnalyticDistributionWithTemplate(contractLine, contract);
    response.setValue("analyticMoveLineList", contractLine.getAnalyticMoveLineList());
}
Also used : Context(com.axelor.rpc.Context) ContractLine(com.axelor.apps.contract.db.ContractLine) Contract(com.axelor.apps.contract.db.Contract)

Example 3 with ContractLine

use of com.axelor.apps.contract.db.ContractLine 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 4 with ContractLine

use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.

the class ContractServiceImpl method checkInvoicedAdditionalContractLine.

protected void checkInvoicedAdditionalContractLine(Contract contract) throws AxelorException {
    Contract origin = find(contract.getId());
    List<ContractLine> lineInvoiced = origin.getAdditionalBenefitContractLineList().stream().filter(ContractLine::getIsInvoiced).collect(Collectors.toList());
    for (ContractLine line : contract.getAdditionalBenefitContractLineList()) {
        if (lineInvoiced.contains(line)) {
            lineInvoiced.remove(line);
        }
    }
    if (!lineInvoiced.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONTRACT_CANT_REMOVE_INVOICED_LINE));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ContractLine(com.axelor.apps.contract.db.ContractLine) InvoiceGeneratorContract(com.axelor.apps.contract.generator.InvoiceGeneratorContract) Contract(com.axelor.apps.contract.db.Contract)

Example 5 with ContractLine

use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.

the class ContractServiceImpl method mergeConsumptionLines.

@Override
public Multimap<ContractLine, ConsumptionLine> mergeConsumptionLines(Contract contract) {
    Multimap<ContractLine, ConsumptionLine> mergedLines = HashMultimap.create();
    Stream<ConsumptionLine> lineStream = contract.getConsumptionLineList().stream().filter(c -> !c.getIsInvoiced());
    if (contract.getCurrentContractVersion().getIsConsumptionBeforeEndDate()) {
        lineStream = lineStream.filter(line -> line.getLineDate().isBefore(contract.getInvoicePeriodEndDate()));
    }
    lineStream.forEach(line -> {
        ContractVersion version = contract.getCurrentContractVersion();
        if (isFullProrated(contract)) {
            version = versionService.getContractVersion(contract, line.getLineDate());
        }
        if (version == null) {
            line.setIsError(true);
        } else {
            ContractLine matchLine = contractLineRepo.findOneBy(version, line.getProduct(), line.getReference(), true);
            if (matchLine == null) {
                line.setIsError(true);
            } else {
                matchLine.setQty(matchLine.getQty().add(line.getQty()));
                contractLineService.computeTotal(matchLine);
                line.setIsError(false);
                line.setContractLine(matchLine);
                mergedLines.put(matchLine, line);
            }
        }
    });
    return mergedLines;
}
Also used : ConsumptionLine(com.axelor.apps.contract.db.ConsumptionLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) ConsumptionLine(com.axelor.apps.contract.db.ConsumptionLine) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ContractLine(com.axelor.apps.contract.db.ContractLine) InvoiceGeneratorContract(com.axelor.apps.contract.generator.InvoiceGeneratorContract) ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) HashMultimap(com.google.common.collect.HashMultimap) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxLine(com.axelor.apps.account.db.TaxLine) FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) RoundingMode(java.math.RoundingMode) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) DurationService(com.axelor.apps.base.service.DurationService) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ContractVersionRepository(com.axelor.apps.contract.db.repo.ContractVersionRepository) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) PriceListRepository(com.axelor.apps.base.db.repo.PriceListRepository) ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.contract.exception.IExceptionMessage) AxelorException(com.axelor.exception.AxelorException) ConsumptionLineRepository(com.axelor.apps.contract.db.repo.ConsumptionLineRepository) I18n(com.axelor.i18n.I18n) ContractTemplate(com.axelor.apps.contract.db.ContractTemplate) DateTool(com.axelor.apps.tool.date.DateTool) PriceListLineRepository(com.axelor.apps.base.db.repo.PriceListLineRepository) InvoiceServiceImpl(com.axelor.apps.account.service.invoice.InvoiceServiceImpl) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) ContractLineRepository(com.axelor.apps.contract.db.repo.ContractLineRepository) Invoice(com.axelor.apps.account.db.Invoice) Account(com.axelor.apps.account.db.Account) Contract(com.axelor.apps.contract.db.Contract) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) Collections(java.util.Collections) AuthUtils(com.axelor.auth.AuthUtils) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ContractLine(com.axelor.apps.contract.db.ContractLine) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Aggregations

ContractLine (com.axelor.apps.contract.db.ContractLine)10 Contract (com.axelor.apps.contract.db.Contract)6 ContractVersion (com.axelor.apps.contract.db.ContractVersion)5 ContractLineService (com.axelor.apps.contract.service.ContractLineService)4 Product (com.axelor.apps.base.db.Product)3 InvoiceGeneratorContract (com.axelor.apps.contract.generator.InvoiceGeneratorContract)3 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 Invoice (com.axelor.apps.account.db.Invoice)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