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;
}
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);
}
}
}
Aggregations