use of com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceGenerator.
@Override
public InvoiceGenerator createInvoiceGenerator(SaleOrder saleOrder, boolean isRefund) throws AxelorException {
if (saleOrder.getCurrency() == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), saleOrder.getSaleOrderSeq());
}
// do not use invoiced partner if the option is disabled
if (!appSupplychainService.getAppSupplychain().getActivatePartnerRelations()) {
saleOrder.setInvoicedPartner(null);
}
return new InvoiceGeneratorSupplyChain(saleOrder, isRefund) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setHeadOfficeAddress(saleOrder.getClientPartner().getHeadOfficeAddress());
return invoice;
}
};
}
use of com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain 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;
}
Aggregations