Search in sources :

Example 26 with Address

use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createStockMove.

protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    Partner supplierPartner = purchaseOrder.getSupplierPartner();
    Company company = purchaseOrder.getCompany();
    Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
    StockLocation startLocation = getStartStockLocation(purchaseOrder);
    StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    stockMove.setOriginId(purchaseOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    stockMove.setTradingName(purchaseOrder.getTradingName());
    stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    qualityStockMove.setOriginId(purchaseOrder.getId());
    qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    qualityStockMove.setTradingName(purchaseOrder.getTradingName());
    qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
    } else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
    }
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
        if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
            this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
        }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(stockMove);
        stockMoveIdList.add(stockMove.getId());
    }
    if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(qualityStockMove);
        stockMoveIdList.add(qualityStockMove.getId());
    }
    return stockMoveIdList;
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Address(com.axelor.apps.base.db.Address) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) PartnerService(com.axelor.apps.base.service.PartnerService) BigDecimal(java.math.BigDecimal) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Partner(com.axelor.apps.base.db.Partner)

Example 27 with Address

use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.

the class ImportAddress method importAddress.

public Object importAddress(Object bean, Map<String, Object> values) {
    Address address = (Address) bean;
    address.setFullName(addressService.computeFullName(address));
    address.setZip(addressService.getZipCode(address));
    return address;
}
Also used : Address(com.axelor.apps.base.db.Address)

Example 28 with Address

use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.

the class EmploymentContractService method employmentContractExportSilae.

public void employmentContractExportSilae(EmploymentContract employmentContract, List<String[]> list) {
    String[] item = new String[21];
    item[0] = employmentContract.getId().toString();
    item[1] = employmentContract.getStartDate() == null ? "" : employmentContract.getStartDate().toString();
    item[2] = employmentContract.getEndDate() == null ? "" : employmentContract.getEndDate().toString();
    Employee employee = employmentContract.getEmployee();
    item[4] = employee.getMaritalName();
    Partner contactPartner = employee.getContactPartner();
    if (contactPartner != null) {
        item[3] = contactPartner.getName();
        item[5] = contactPartner.getFirstName();
        Address mainAddress = contactPartner.getMainAddress();
        if (mainAddress != null) {
            item[6] = mainAddress.getAddressL4();
            item[7] = mainAddress.getAddressL2();
            item[8] = mainAddress.getZip();
            if (mainAddress.getCity() != null) {
                item[9] = mainAddress.getCity().getName();
            } else {
                item[9] = "";
            }
        }
        item[10] = contactPartner.getMobilePhone();
        item[11] = contactPartner.getFixedPhone();
        item[12] = contactPartner.getEmailAddress() == null ? "" : contactPartner.getEmailAddress().getAddress();
    }
    item[13] = employee.getBirthDate() == null ? "" : employee.getBirthDate().toString();
    Department birthDepartment = employee.getDepartmentOfBirth();
    if (birthDepartment != null) {
        item[14] = birthDepartment.getName();
        item[16] = !birthDepartment.getCode().equals("99") ? "FR - FRANCE" : "Oui";
    }
    item[15] = employee.getCityOfBirth() == null ? "" : employee.getCityOfBirth().getName();
    item[17] = employee.getSocialSecurityNumber();
    item[18] = employmentContract.getPayCompany().getName();
    item[19] = employmentContract.getContractType() == null ? "" : employmentContract.getContractType().getId().toString();
    item[20] = employee.getMaidenName();
    list.add(item);
}
Also used : Department(com.axelor.apps.base.db.Department) Employee(com.axelor.apps.hr.db.Employee) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner)

Example 29 with Address

use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.

the class OpportunityServiceImpl method createClientFromLead.

@Override
@Transactional(rollbackOn = { Exception.class })
public Partner createClientFromLead(Opportunity opportunity) throws AxelorException {
    Lead lead = opportunity.getLead();
    if (lead == null) {
        throw new AxelorException(opportunity, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAD_PARTNER));
    }
    String name = lead.getFullName();
    Address address = null;
    if (lead.getPrimaryAddress() != null) {
        // avoids printing 'null'
        String addressL6 = lead.getPrimaryPostalCode() == null ? "" : lead.getPrimaryPostalCode() + " ";
        addressL6 += lead.getPrimaryCity() == null ? "" : lead.getPrimaryCity().getName();
        address = addressService.createAddress(null, null, lead.getPrimaryAddress(), null, addressL6, lead.getPrimaryCountry());
        address.setFullName(addressService.computeFullName(address));
    }
    EmailAddress email = null;
    if (lead.getEmailAddress() != null) {
        email = new EmailAddress(lead.getEmailAddress().getAddress());
    }
    Partner partner = Beans.get(PartnerService.class).createPartner(name, null, lead.getFixedPhone(), lead.getMobilePhone(), email, opportunity.getCurrency(), address, address, true);
    opportunity.setPartner(partner);
    opportunityRepo.save(opportunity);
    return partner;
}
Also used : AxelorException(com.axelor.exception.AxelorException) EmailAddress(com.axelor.apps.message.db.EmailAddress) Address(com.axelor.apps.base.db.Address) Lead(com.axelor.apps.crm.db.Lead) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) EmailAddress(com.axelor.apps.message.db.EmailAddress) Transactional(com.google.inject.persist.Transactional)

Example 30 with Address

use of com.axelor.apps.base.db.Address 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)

Aggregations

Address (com.axelor.apps.base.db.Address)32 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)18 AxelorException (com.axelor.exception.AxelorException)15 Partner (com.axelor.apps.base.db.Partner)13 AddressService (com.axelor.apps.base.service.AddressService)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 EmailAddress (com.axelor.apps.message.db.EmailAddress)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PartnerService (com.axelor.apps.base.service.PartnerService)5 Map (java.util.Map)4 Invoice (com.axelor.apps.account.db.Invoice)3 Company (com.axelor.apps.base.db.Company)3 Country (com.axelor.apps.base.db.Country)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 StockMove (com.axelor.apps.stock.db.StockMove)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3