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