use of com.axelor.apps.account.service.invoice.InvoiceService in project axelor-open-suite by axelor.
the class InvoiceController method ventilate.
/**
* Called from invoice form view, on clicking ventilate button. Call {@link
* InvoiceService#ventilate(Invoice)}.
*
* @param request
* @param response
*/
public void ventilate(ActionRequest request, ActionResponse response) {
Invoice invoice = request.getContext().asType(Invoice.class);
invoice = Beans.get(InvoiceRepository.class).find(invoice.getId());
try {
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
long tracebackCount = traceBackService.countMessageTraceBack(invoice);
Beans.get(InvoiceService.class).ventilate(invoice);
response.setReload(true);
if (traceBackService.countMessageTraceBack(invoice) > tracebackCount) {
traceBackService.findLastMessageTraceBack(invoice).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.service.invoice.InvoiceService in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoInvoice.
@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
PartnerService partnerService = Beans.get(PartnerService.class);
InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
InvoiceService invoiceService = Beans.get(InvoiceService.class);
boolean isPurchase;
// set the status
int generatedOperationTypeSelect;
int priceListRepositoryType;
switch(invoice.getOperationTypeSelect()) {
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
default:
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
}
Company intercoCompany = findIntercoCompany(invoice.getPartner());
Partner intercoPartner = invoice.getCompany().getPartner();
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
intercoInvoice.setCompany(intercoCompany);
intercoInvoice.setPartner(intercoPartner);
intercoInvoice.setAddress(intercoAddress);
intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
intercoInvoice.setPaymentMode(intercoPaymentMode);
intercoInvoice.setBankDetails(intercoBankDetails);
Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
if (accountingSituation != null) {
intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
}
intercoInvoice.setPriceList(intercoPriceList);
intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
intercoInvoice.setCreatedByInterco(true);
intercoInvoice.setInterco(false);
intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
if (intercoInvoice.getInvoiceLineList() != null) {
for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
invoiceLine.setInvoice(intercoInvoice);
createIntercoInvoiceLine(invoiceLine, isPurchase);
}
}
invoiceService.compute(intercoInvoice);
intercoInvoice.setExternalReference(invoice.getInvoiceId());
intercoInvoice = invoiceRepository.save(intercoInvoice);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
Beans.get(InvoiceService.class).validate(intercoInvoice);
}
invoice.setExternalReference(intercoInvoice.getInvoiceId());
return intercoInvoice;
}
Aggregations