use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method mergeInvoice.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice mergeInvoice(List<Invoice> invoiceList, Company company, Currency currency, Partner partner, Partner contactPartner, PriceList priceList, PaymentMode paymentMode, PaymentCondition paymentCondition) throws AxelorException {
String numSeq = "";
String externalRef = "";
for (Invoice invoiceLocal : invoiceList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
if (invoiceLocal.getInternalReference() != null) {
numSeq += invoiceLocal.getInternalReference();
}
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (invoiceLocal.getExternalReference() != null) {
externalRef += invoiceLocal.getExternalReference();
}
}
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, paymentCondition, paymentMode, partnerService.getInvoicingAddress(partner), partner, contactPartner, currency, priceList, numSeq, externalRef, null, company.getDefaultBankDetails(), null, null) {
@Override
public Invoice generate() throws AxelorException {
return super.createInvoiceHeader();
}
};
Invoice invoiceMerged = invoiceGenerator.generate();
List<InvoiceLine> invoiceLines = this.getInvoiceLinesFromInvoiceList(invoiceList);
invoiceGenerator.populate(invoiceMerged, invoiceLines);
this.setInvoiceForInvoiceLines(invoiceLines, invoiceMerged);
invoiceRepo.save(invoiceMerged);
return invoiceMerged;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceAndLines.
public Invoice createInvoiceAndLines(SaleOrder saleOrder, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice, int operationSubTypeSelect, Account partnerAccount) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
Invoice invoice = invoiceGenerator.generate();
List<InvoiceLine> invoiceLinesList = (taxLineList != null && !taxLineList.isEmpty()) ? this.createInvoiceLinesFromTax(invoice, taxLineList, invoicingProduct, percentToInvoice) : this.createInvoiceLinesFromSO(invoice, saleOrder, invoicingProduct, percentToInvoice);
invoiceGenerator.populate(invoice, invoiceLinesList);
invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
invoice.setOperationSubTypeSelect(operationSubTypeSelect);
if (partnerAccount != null) {
Partner partner = invoice.getPartner();
if (partner != null) {
partnerAccount = Beans.get(FiscalPositionAccountService.class).getAccount(partner.getFiscalPosition(), partnerAccount);
}
invoice.setPartnerAccount(partnerAccount);
}
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator 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.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiIncomingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyInInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiIncomingStockMove(dummyInvoice, stockMove);
}
/* check if some other fields are different and assign a default value */
if (dummyInvoice.getAddress() == null) {
dummyInvoice.setAddress(Beans.get(PartnerService.class).getInvoicingAddress(dummyInvoice.getPartner()));
dummyInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(dummyInvoice.getAddress()));
}
fillReferenceInvoiceFromMultiInStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE, dummyInvoice.getCompany(), dummyInvoice.getPaymentCondition(), dummyInvoice.getPaymentMode(), dummyInvoice.getAddress(), dummyInvoice.getPartner(), dummyInvoice.getContactPartner(), dummyInvoice.getCurrency(), dummyInvoice.getPriceList(), dummyInvoice.getInternalReference(), dummyInvoice.getExternalReference(), dummyInvoice.getInAti(), null, dummyInvoice.getTradingName(), null) {
@Override
public Invoice generate() throws AxelorException {
return super.createInvoiceHeader();
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
createdInvoiceLines.forEach(this::negateInvoiceLinePrice);
}
invoiceLineList.addAll(createdInvoiceLines);
}
invoiceGenerator.populate(invoice, invoiceLineList);
invoiceRepository.save(invoice);
invoice = toPositivePriceInvoice(invoice);
if (invoice.getExTaxTotal().signum() == 0 && stockMoveList.stream().allMatch(StockMove::getIsReversion)) {
invoice.setOperationTypeSelect(InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceFromSaleOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createInvoiceFromSaleOrder(StockMove stockMove, SaleOrder saleOrder, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
// we block if we are trying to invoice partially if config is deactivated
if (!supplyChainConfigService.getSupplyChainConfig(stockMove.getCompany()).getActivateOutStockMovePartialInvoicing() && computeNonCanceledInvoiceQty(stockMove).signum() > 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_PARTIAL_INVOICE_ERROR), stockMove.getStockMoveSeq());
}
InvoiceGenerator invoiceGenerator = saleOrderInvoiceService.createInvoiceGenerator(saleOrder, stockMove.getIsReversion());
Invoice invoice = invoiceGenerator.generate();
checkSplitSalePartiallyInvoicedStockMoveLines(stockMove, stockMove.getStockMoveLineList());
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;
}
invoice.setSaleOrder(saleOrder);
this.extendInternalReference(stockMove, invoice);
invoice.setDeliveryAddress(stockMove.getToAddress());
invoice.setDeliveryAddressStr(stockMove.getToAddressStr());
invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
// fill default advance payment invoice
if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
invoice.setAdvancePaymentInvoiceSet(Beans.get(InvoiceService.class).getDefaultAdvancePaymentInvoice(invoice));
}
invoice.setPartnerTaxNbr(saleOrder.getClientPartner().getTaxNbr());
if (!Strings.isNullOrEmpty(saleOrder.getInvoiceComments())) {
invoice.setNote(saleOrder.getInvoiceComments());
}
if (ObjectUtils.isEmpty(invoice.getProformaComments()) && !Strings.isNullOrEmpty(saleOrder.getProformaComments())) {
invoice.setProformaComments(saleOrder.getProformaComments());
}
Set<StockMove> stockMoveSet = invoice.getStockMoveSet();
if (stockMoveSet == null) {
stockMoveSet = new HashSet<>();
invoice.setStockMoveSet(stockMoveSet);
}
stockMoveSet.add(stockMove);
invoiceRepository.save(invoice);
}
return invoice;
}
Aggregations