use of com.axelor.apps.base.service.AddressService in project axelor-open-suite by axelor.
the class AddressController method updateLatLong.
public void updateLatLong(ActionRequest request, ActionResponse response) {
AddressService addressService = Beans.get(AddressService.class);
try {
Address address = request.getContext().asType(Address.class);
address = Beans.get(AddressRepository.class).find(address.getId());
addressService.resetLatLong(address);
addressService.updateLatLong(address);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.service.AddressService in project axelor-open-suite by axelor.
the class SaleOrderServiceImpl method computeAddressStr.
@Override
public void computeAddressStr(SaleOrder saleOrder) {
AddressService addressService = Beans.get(AddressService.class);
saleOrder.setMainInvoicingAddressStr(addressService.computeAddressStr(saleOrder.getMainInvoicingAddress()));
saleOrder.setDeliveryAddressStr(addressService.computeAddressStr(saleOrder.getDeliveryAddress()));
}
use of com.axelor.apps.base.service.AddressService in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiOutgoingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
Set<Address> deliveryAddressSet = new HashSet<>();
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyOutInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiOutgoingStockMove(dummyInvoice, stockMove);
if (stockMove.getToAddressStr() != null) {
deliveryAddressSet.add(stockMove.getToAddress());
}
}
/* 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()));
}
fillReferenceInvoiceFromMultiOutStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, 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(), dummyInvoice.getGroupProductsOnPrintings()) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setPartnerTaxNbr(partner.getTaxNbr());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
StringBuilder deliveryAddressStr = new StringBuilder();
AddressService addressService = Beans.get(AddressService.class);
for (Address address : deliveryAddressSet) {
deliveryAddressStr.append(addressService.computeAddressStr(address).replaceAll("\n", ", ") + "\n");
}
invoice.setDeliveryAddressStr(deliveryAddressStr.toString());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
stockMoveInvoiceService.checkSplitSalePartiallyInvoicedStockMoveLines(stockMoveLocal, stockMoveLocal.getStockMoveLineList());
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
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_CLIENT_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
use of com.axelor.apps.base.service.AddressService in project axelor-open-suite by axelor.
the class StockMoveToolServiceImpl method computeAddressStr.
@Override
public void computeAddressStr(StockMove stockMove) {
AddressService addressService = Beans.get(AddressService.class);
stockMove.setFromAddressStr(addressService.computeAddressStr(stockMove.getFromAddress()));
stockMove.setToAddressStr(addressService.computeAddressStr(stockMove.getToAddress()));
}
Aggregations