use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class PartnerServiceImpl method updatePartnerAddress.
/**
* Updates M2O and O2M fields of partner that manage partner addresses. This method ensures
* consistency between these two fields.
*
* @param partner
* @throws AxelorException
*/
protected void updatePartnerAddress(Partner partner) throws AxelorException {
Address address = partner.getMainAddress();
if (!partner.getIsContact() && !partner.getIsEmployee()) {
if (partner.getPartnerAddressList() != null) {
partner.setMainAddress(checkDefaultAddress(partner));
}
} else if (address == null) {
partner.removePartnerAddressListItem(JPA.all(PartnerAddress.class).filter("self.partner = :partnerId AND self.isDefaultAddr = 't'").bind("partnerId", partner.getId()).fetchOne());
} else if (partner.getPartnerAddressList() != null && partner.getPartnerAddressList().stream().map(PartnerAddress::getAddress).noneMatch(address::equals)) {
PartnerAddress mainAddress = new PartnerAddress();
mainAddress.setAddress(address);
mainAddress.setIsDefaultAddr(true);
mainAddress.setIsDeliveryAddr(true);
mainAddress.setIsInvoicingAddr(true);
partner.addPartnerAddressListItem(mainAddress);
}
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class MapRestServiceImpl method setData.
@Override
public void setData(ObjectNode mainNode, ArrayNode arrayNode) throws AxelorException, JSONException {
mainNode.put("status", 0);
mainNode.set("data", arrayNode);
Optional<Address> optionalAddress = Beans.get(UserService.class).getUserActiveCompanyAddress();
if (optionalAddress.isPresent()) {
Optional<Pair<BigDecimal, BigDecimal>> latLong = Beans.get(AddressService.class).getOrUpdateLatLong(optionalAddress.get());
if (latLong.isPresent()) {
JsonNodeFactory factory = JsonNodeFactory.instance;
ObjectNode objectNode = factory.objectNode();
objectNode.put("lat", latLong.get().getLeft());
objectNode.put("lng", latLong.get().getRight());
mainNode.set("company", objectNode);
}
}
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressServiceImpl method createAddress.
@Override
public Address createAddress(String addressL2, String addressL3, String addressL4, String addressL5, String addressL6, Country addressL7Country) {
Address address = new Address();
address.setAddressL2(addressL2);
address.setAddressL3(addressL3);
address.setAddressL4(addressL4);
address.setAddressL5(addressL5);
address.setAddressL6(addressL6);
address.setAddressL7Country(addressL7Country);
return address;
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressServiceImpl method export.
@Override
public int export(String path) throws IOException {
List<Address> addresses = addressRepo.all().filter("self.certifiedOk IS FALSE").fetch();
CSVWriter csv = new CSVWriter(new java.io.FileWriter(path), "|".charAt(0), CSVWriter.NO_QUOTE_CHARACTER);
List<String> header = new ArrayList<>();
header.add("Id");
header.add("AddressL1");
header.add("AddressL2");
header.add("AddressL3");
header.add("AddressL4");
header.add("AddressL5");
header.add("AddressL6");
header.add("CodeINSEE");
csv.writeNext(header.toArray(new String[header.size()]));
List<String> items = new ArrayList<>();
for (Address a : addresses) {
items.add(a.getId() != null ? a.getId().toString() : "");
items.add(a.getAddressL2() != null ? a.getAddressL2() : "");
items.add(a.getAddressL3() != null ? a.getAddressL3() : "");
items.add(a.getAddressL4() != null ? a.getAddressL4() : "");
items.add(a.getAddressL5() != null ? a.getAddressL5() : "");
items.add(a.getAddressL6() != null ? a.getAddressL6() : "");
items.add(a.getInseeCode() != null ? a.getInseeCode() : "");
csv.writeNext(items.toArray(new String[items.size()]));
items.clear();
}
csv.close();
LOG.info("{} exported", path);
return addresses.size();
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressController method createPartnerAddress.
public void createPartnerAddress(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
Context parentContext = context.getParent();
if (parentContext.isEmpty()) {
return;
}
String parentModel = (String) parentContext.get("_model");
LOG.debug("Create partner address : Parent model = {}", parentModel);
String partnerField = PartnerAddressRepository.modelPartnerFieldMap.get(parentModel);
LOG.debug("Create partner address : Parent field = {}", partnerField);
Partner partner = null;
if (parentContext.get(partnerField) instanceof Partner) {
partner = (Partner) parentContext.get(partnerField);
} else if (parentContext.get(partnerField) instanceof Map) {
partner = Mapper.toBean(Partner.class, (Map<String, Object>) parentContext.get(partnerField));
}
LOG.debug("Create partner address : Partner = {}", partner);
if (partner == null || partner.getId() == null) {
return;
}
Address address = context.asType(Address.class);
PartnerAddress partnerAddress = Beans.get(PartnerAddressRepository.class).all().filter("self.partner.id = ? AND self.address.id = ?", partner.getId(), address.getId()).fetchOne();
LOG.debug("Create partner address : Partner Address = {}", partnerAddress);
if (partnerAddress == null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
address = Beans.get(AddressRepository.class).find(address.getId());
Boolean invoicing = (Boolean) context.get("isInvoicingAddr");
if (invoicing == null) {
invoicing = false;
}
Boolean delivery = (Boolean) context.get("isDeliveryAddr");
if (delivery == null) {
delivery = false;
}
Boolean isDefault = (Boolean) context.get("isDefault");
if (isDefault == null) {
isDefault = false;
}
PartnerService partnerService = Beans.get(PartnerService.class);
partnerService.addPartnerAddress(partner, address, isDefault, invoicing, delivery);
partnerService.savePartner(partner);
}
}
Aggregations