Search in sources :

Example 1 with AddressService

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);
    }
}
Also used : AddressService(com.axelor.apps.base.service.AddressService) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 2 with AddressService

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()));
}
Also used : AddressService(com.axelor.apps.base.service.AddressService)

Example 3 with AddressService

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);
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) Address(com.axelor.apps.base.db.Address) AddressService(com.axelor.apps.base.service.AddressService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 4 with AddressService

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()));
}
Also used : AddressService(com.axelor.apps.base.service.AddressService)

Aggregations

AddressService (com.axelor.apps.base.service.AddressService)4 Address (com.axelor.apps.base.db.Address)2 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)1 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)1 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)1 StockMove (com.axelor.apps.stock.db.StockMove)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1