use of com.axelor.apps.contract.db.Contract 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());
}
use of com.axelor.apps.contract.db.Contract 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.Contract 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));
}
}
use of com.axelor.apps.contract.db.Contract 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;
}
use of com.axelor.apps.contract.db.Contract in project axelor-open-suite by axelor.
the class ContractRepository method copy.
@Override
public Contract copy(Contract entity, boolean deep) {
Contract contract = super.copy(entity, deep);
ContractVersion version = Beans.get(ContractVersionRepository.class).copy(entity);
contract.setCurrentContractVersion(version);
return contract;
}
Aggregations