Search in sources :

Example 1 with PartnerAddressRepository

use of com.axelor.apps.base.db.repo.PartnerAddressRepository 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 2 with PartnerAddressRepository

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

Aggregations

PartnerAddress (com.axelor.apps.base.db.PartnerAddress)2 PartnerAddressRepository (com.axelor.apps.base.db.repo.PartnerAddressRepository)2 Transactional (com.google.inject.persist.Transactional)1