use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceFromPurchaseOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createInvoiceFromPurchaseOrder(StockMove stockMove, PurchaseOrder purchaseOrder, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
if (!supplyChainConfigService.getSupplyChainConfig(stockMove.getCompany()).getActivateIncStockMovePartialInvoicing() && computeNonCanceledInvoiceQty(stockMove).signum() > 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_PARTIAL_INVOICE_ERROR));
}
InvoiceGenerator invoiceGenerator = purchaseOrderInvoiceService.createInvoiceGenerator(purchaseOrder, stockMove.getIsReversion());
Invoice invoice = invoiceGenerator.generate();
invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, stockMove, stockMove.getStockMoveLineList(), qtyToInvoiceMap));
if (invoice != null) {
// do not create empty invoices
if (invoice.getInvoiceLineList() == null || invoice.getInvoiceLineList().isEmpty()) {
return null;
}
this.extendInternalReference(stockMove, invoice);
invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
if (invoice != null) {
Set<StockMove> stockMoveSet = invoice.getStockMoveSet();
if (stockMoveSet == null) {
stockMoveSet = new HashSet<>();
invoice.setStockMoveSet(stockMoveSet);
}
stockMoveSet.add(stockMove);
}
invoiceRepository.save(invoice);
}
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceFromOrderlessStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createInvoiceFromOrderlessStockMove(StockMove stockMove, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
int stockMoveType = stockMove.getTypeSelect();
int invoiceOperationType;
if (stockMove.getIsReversion()) {
if (stockMoveType == StockMoveRepository.TYPE_INCOMING) {
invoiceOperationType = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
} else if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
invoiceOperationType = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
} else {
return null;
}
} else {
if (stockMoveType == StockMoveRepository.TYPE_INCOMING) {
invoiceOperationType = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
} else if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
invoiceOperationType = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
} else {
return null;
}
}
// do not use invoiced partner if the option is disabled
if (!appSupplychainService.getAppSupplychain().getActivatePartnerRelations()) {
stockMove.setInvoicedPartner(null);
}
InvoiceGenerator invoiceGenerator = new InvoiceGeneratorSupplyChain(stockMove, invoiceOperationType) {
@Override
public Invoice generate() throws AxelorException {
return super.createInvoiceHeader();
}
};
Invoice invoice = invoiceGenerator.generate();
invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, stockMove, stockMove.getStockMoveLineList(), qtyToInvoiceMap));
if (invoice != null) {
this.extendInternalReference(stockMove, invoice);
invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
invoice.setHeadOfficeAddress(stockMove.getPartner().getHeadOfficeAddress());
}
invoiceRepository.save(invoice);
if (invoice != null) {
Set<StockMove> stockMoveSet = invoice.getStockMoveSet();
if (stockMoveSet == null) {
stockMoveSet = new HashSet<>();
invoice.setStockMoveSet(stockMoveSet);
}
stockMoveSet.add(stockMove);
}
invoiceRepository.save(invoice);
}
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class InvoicingProjectService method generateInvoice.
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(InvoicingProject invoicingProject) throws AxelorException {
Project project = invoicingProject.getProject();
Partner customer = project.getClientPartner();
Partner customerContact = project.getContactPartner();
if (invoicingProject.getSaleOrderLineSet().isEmpty() && invoicingProject.getPurchaseOrderLineSet().isEmpty() && invoicingProject.getLogTimesSet().isEmpty() && invoicingProject.getExpenseLineSet().isEmpty() && invoicingProject.getProjectSet().isEmpty() && invoicingProject.getProjectTaskSet().isEmpty()) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_EMPTY));
}
if (invoicingProject.getProject() == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT));
}
if (invoicingProject.getProject().getClientPartner() == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_PARTNER));
}
if (customerContact == null && customer.getContactPartnerSet().size() == 1) {
customerContact = customer.getContactPartnerSet().iterator().next();
}
Company company = this.getRootCompany(project);
if (company == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_COMPANY));
}
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, customer.getPaymentCondition(), customer.getInPaymentMode(), partnerService.getInvoicingAddress(customer), customer, customerContact, customer.getCurrency(), Beans.get(PartnerPriceListService.class).getDefaultPriceList(customer, PriceListRepository.TYPE_SALE), null, null, null, null, null, null) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setProject(project);
invoice.setPriceList(project.getPriceList());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
invoice.setDisplayTimesheetOnPrinting(accountConfig.getDisplayTimesheetOnPrinting());
invoice.setDisplayExpenseOnPrinting(accountConfig.getDisplayExpenseOnPrinting());
invoiceGenerator.populate(invoice, this.populate(invoice, invoicingProject));
Beans.get(InvoiceRepository.class).save(invoice);
invoicingProject.setInvoice(invoice);
invoicingProject.setStatusSelect(InvoicingProjectRepository.STATUS_GENERATED);
invoicingProjectRepo.save(invoicingProject);
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method compute.
/**
* Fonction permettant de calculer l'intégralité d'une facture :
*
* <ul>
* <li>Détermine les taxes;
* <li>Détermine la TVA;
* <li>Détermine les totaux.
* </ul>
*
* (Transaction)
*
* @param invoice Une facture.
* @throws AxelorException
*/
@Override
public Invoice compute(final Invoice invoice) throws AxelorException {
log.debug("Calcul de la facture");
InvoiceGenerator invoiceGenerator = new InvoiceGenerator() {
@Override
public Invoice generate() throws AxelorException {
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
if (invoice.getInvoiceLineList() != null) {
invoiceLines.addAll(invoice.getInvoiceLineList());
}
populate(invoice, invoiceLines);
return invoice;
}
};
Invoice invoice1 = invoiceGenerator.generate();
invoice1.setAdvancePaymentInvoiceSet(this.getDefaultAdvancePaymentInvoice(invoice1));
return invoice1;
}
Aggregations