Search in sources :

Example 1 with PartnerAddress

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

the class PartnerBaseRepository method copy.

@Override
public Partner copy(Partner partner, boolean deep) {
    Partner copy = super.copy(partner, deep);
    copy.setPartnerSeq(null);
    copy.setEmailAddress(null);
    PartnerAddressRepository partnerAddressRepository = Beans.get(PartnerAddressRepository.class);
    List<PartnerAddress> partnerAddressList = Lists.newArrayList();
    if (deep && copy.getPartnerAddressList() != null) {
        for (PartnerAddress partnerAddress : copy.getPartnerAddressList()) {
            partnerAddressList.add(partnerAddressRepository.copy(partnerAddress, deep));
        }
    }
    copy.setPartnerAddressList(partnerAddressList);
    copy.setBlockingList(null);
    copy.setBankDetailsList(null);
    return copy;
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Partner(com.axelor.apps.base.db.Partner)

Example 2 with PartnerAddress

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

the class PartnerServiceImpl method getAddress.

protected Address getAddress(Partner partner, String querySpecific, String queryComman) {
    if (partner != null) {
        PartnerAddressRepository partnerAddressRepo = Beans.get(PartnerAddressRepository.class);
        List<PartnerAddress> partnerAddressList = partnerAddressRepo.all().filter(querySpecific, partner.getId()).fetch();
        if (partnerAddressList.isEmpty()) {
            partnerAddressList = partnerAddressRepo.all().filter(queryComman, partner.getId()).fetch();
            if (partnerAddressList.isEmpty()) {
                partnerAddressList = partnerAddressRepo.all().filter("self.partner.id = ?1", partner.getId()).fetch();
            }
        }
        if (partnerAddressList.size() == 1) {
            return partnerAddressList.get(0).getAddress();
        }
        for (PartnerAddress partnerAddress : partnerAddressList) {
            if (partnerAddress.getIsDefaultAddr()) {
                return partnerAddress.getAddress();
            }
        }
    }
    return null;
}
Also used : PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) PartnerAddress(com.axelor.apps.base.db.PartnerAddress)

Example 3 with PartnerAddress

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

the class PartnerServiceImpl method checkDefaultAddress.

/**
 * Ensures that there is exactly one default invoicing address and no more than one default
 * delivery address. If the partner address list is valid, returns the default invoicing address.
 *
 * @param partner
 * @throws AxelorException
 */
protected Address checkDefaultAddress(Partner partner) throws AxelorException {
    List<PartnerAddress> partnerAddressList = partner.getPartnerAddressList();
    Address defaultInvoicingAddress = null;
    Address defaultDeliveryAddress = null;
    if (partnerAddressList != null) {
        for (PartnerAddress partnerAddress : partnerAddressList) {
            if (partnerAddress.getIsDefaultAddr() && partnerAddress.getIsInvoicingAddr()) {
                if (defaultInvoicingAddress != null) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ADDRESS_8));
                }
                defaultInvoicingAddress = partnerAddress.getAddress();
            }
            if (partnerAddress.getIsDefaultAddr() && partnerAddress.getIsDeliveryAddr()) {
                if (defaultDeliveryAddress != null) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ADDRESS_9));
                }
                defaultDeliveryAddress = partnerAddress.getAddress();
            }
        }
    }
    return defaultInvoicingAddress;
}
Also used : AxelorException(com.axelor.exception.AxelorException) EmailAddress(com.axelor.apps.message.db.EmailAddress) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress)

Example 4 with PartnerAddress

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

the class PartnerServiceImpl method resetDefaultAddress.

@Transactional
@Override
public void resetDefaultAddress(Partner partner, String addrTypeQuery) {
    if (partner.getId() != null) {
        PartnerAddressRepository partnerAddressRepo = Beans.get(PartnerAddressRepository.class);
        PartnerAddress partnerAddress = partnerAddressRepo.all().filter("self.partner.id = ? AND self.isDefaultAddr = true" + addrTypeQuery, partner.getId()).fetchOne();
        if (partnerAddress != null) {
            partnerAddress.setIsDefaultAddr(false);
            partnerAddressRepo.save(partnerAddress);
        }
    }
}
Also used : PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Transactional(com.google.inject.persist.Transactional)

Example 5 with PartnerAddress

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

the class PartnerServiceImpl method createPartnerAddress.

private PartnerAddress createPartnerAddress(Address address, Boolean isDefault) {
    PartnerAddress partnerAddress = new PartnerAddress();
    partnerAddress.setAddress(address);
    partnerAddress.setIsDefaultAddr(isDefault);
    return partnerAddress;
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress)

Aggregations

PartnerAddress (com.axelor.apps.base.db.PartnerAddress)10 Address (com.axelor.apps.base.db.Address)4 Partner (com.axelor.apps.base.db.Partner)3 PartnerAddressRepository (com.axelor.apps.base.db.repo.PartnerAddressRepository)3 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 AxelorException (com.axelor.exception.AxelorException)2 PartnerService (com.axelor.apps.base.service.PartnerService)1 Context (com.axelor.rpc.Context)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Transactional (com.google.inject.persist.Transactional)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1