use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method generateInvoice.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(SaleOrder saleOrder) throws AxelorException {
Invoice invoice = this.createInvoice(saleOrder);
invoice.setDeliveryAddress(saleOrder.getDeliveryAddress());
invoice.setDeliveryAddressStr(saleOrder.getDeliveryAddressStr());
invoiceRepo.save(invoice);
saleOrderRepo.save(fillSaleOrder(saleOrder, invoice));
return invoice;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoice.
@Override
public Invoice createInvoice(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
Invoice invoice = invoiceGenerator.generate();
invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, saleOrderLineList, qtyToInvoiceMap));
invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
return invoice;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoInvoiceLine.
protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
Invoice intercoInvoice = invoiceLine.getInvoice();
Partner partner = intercoInvoice.getPartner();
if (intercoInvoice.getCompany() != null) {
Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
invoiceLine.setAccount(account);
TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
if (invoiceLine.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
}
}
return invoiceLine;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class BudgetSupplychainService method getDate.
@Override
protected Optional<LocalDate> getDate(BudgetDistribution budgetDistribution) {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return super.getDate(budgetDistribution);
}
InvoiceLine invoiceLine = budgetDistribution.getInvoiceLine();
if (invoiceLine == null) {
return Optional.empty();
}
Invoice invoice = invoiceLine.getInvoice();
if (invoice.getPurchaseOrder() != null) {
return Optional.of(invoice.getPurchaseOrder().getOrderDate());
}
return super.getDate(budgetDistribution);
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method generateInvoiceFromTimetableForPurchaseOrder.
@Transactional(rollbackOn = { Exception.class })
protected Invoice generateInvoiceFromTimetableForPurchaseOrder(PurchaseOrder purchaseOrder, List<Long> timetableIdList) throws AxelorException {
if (ObjectUtils.isEmpty(timetableIdList)) {
throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_NO_TIMETABLES_SELECTED));
}
BigDecimal percentSum = BigDecimal.ZERO;
List<Timetable> timetableList = new ArrayList<>();
for (Long timetableId : timetableIdList) {
Timetable timetable = timetableRepo.find(timetableId);
timetableList.add(timetable);
percentSum = percentSum.add(timetable.getPercentage());
}
Invoice invoice = generateInvoiceFromLines(purchaseOrder, percentSum);
for (Timetable timetable : timetableList) {
timetable.setInvoice(invoice);
timetable.setInvoiced(true);
timetableRepo.save(timetable);
}
return invoice;
}
Aggregations