use of com.axelor.apps.base.db.PartnerPriceList in project axelor-open-suite by axelor.
the class PartnerPriceListServiceImpl method checkDates.
@Override
public void checkDates(PartnerPriceList partnerPriceList) throws AxelorException {
Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
if (priceListSet == null) {
return;
}
Set<PriceList> sortedPriceListSet = priceListSet.stream().sorted(Comparator.comparing(priceList -> priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN)).collect(Collectors.toSet());
LocalDate beginDate;
LocalDate previousEndDate = LocalDate.MIN;
String previousTitle = "";
for (PriceList priceList : sortedPriceListSet) {
beginDate = priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN;
if (beginDate.compareTo(previousEndDate) < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.PARTNER_PRICE_LIST_DATE_INCONSISTENT), previousTitle.replace("%", "%%"), priceList.getTitle().replace("%", "%%")), partnerPriceList);
}
previousEndDate = priceList.getApplicationEndDate() != null ? priceList.getApplicationEndDate() : LocalDate.MAX;
previousTitle = priceList.getTitle();
}
}
use of com.axelor.apps.base.db.PartnerPriceList in project axelor-open-suite by axelor.
the class PartnerPriceListController method checkDates.
/**
* Called from partner price list form view call {@link
* PartnerPriceListService#checkDates(PartnerPriceList)} return a warning with the response if
* dates validation fails for the price list set.
*
* @param request
* @param response
*/
public void checkDates(ActionRequest request, ActionResponse response) {
PartnerPriceList partnerPriceList;
Class partnerOrPriceLists = request.getContext().getContextClass();
if (partnerOrPriceLists.equals(Partner.class)) {
partnerPriceList = request.getContext().asType(Partner.class).getSalePartnerPriceList();
} else if (partnerOrPriceLists.equals(PartnerPriceList.class)) {
partnerPriceList = request.getContext().asType(PartnerPriceList.class);
} else {
return;
}
try {
Beans.get(PartnerPriceListService.class).checkDates(partnerPriceList);
} catch (Exception e) {
response.setAlert(e.getMessage());
}
}
use of com.axelor.apps.base.db.PartnerPriceList in project axelor-open-suite by axelor.
the class PartnerPriceListServiceImpl method getDefaultPriceList.
@Override
public PriceList getDefaultPriceList(Partner partner, int priceListTypeSelect) {
if (partner == null) {
return null;
}
partner = Beans.get(PartnerRepository.class).find(partner.getId());
PartnerPriceList partnerPriceList = getPartnerPriceList(partner, priceListTypeSelect);
if (partnerPriceList == null) {
return null;
}
Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
if (priceListSet == null) {
return null;
}
List<PriceList> priceLists = priceListSet.stream().filter(priceList -> (priceList.getApplicationBeginDate() == null || priceList.getApplicationBeginDate().compareTo(appBaseService.getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))) <= 0) && (priceList.getApplicationEndDate() == null || priceList.getApplicationEndDate().compareTo(appBaseService.getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))) >= 0)).collect(Collectors.toList());
if (priceLists.size() == 1) {
return priceLists.get(0);
} else {
return null;
}
}
use of com.axelor.apps.base.db.PartnerPriceList in project axelor-open-suite by axelor.
the class PartnerPriceListServiceImpl method getPriceListDomain.
public String getPriceListDomain(Partner partner, int priceListTypeSelect) {
if (partner == null) {
return "self.id IN (0)";
}
// get all non exclusive partner price lists
List<PartnerPriceList> partnerPriceLists = Beans.get(PartnerPriceListRepository.class).all().filter("self.typeSelect = :_priceListTypeSelect " + "AND self.isExclusive = false").bind("_priceListTypeSelect", priceListTypeSelect).fetch();
// get (maybe exclusive) list for the partner
PartnerPriceList partnerPriceList = getPartnerPriceList(partner, priceListTypeSelect);
if (partnerPriceList != null && partnerPriceList.getIsExclusive()) {
partnerPriceLists.add(partnerPriceList);
}
if (partnerPriceLists.isEmpty()) {
return "self.id IN (0)";
}
List<PriceList> priceLists = partnerPriceLists.stream().flatMap(partnerPriceList1 -> partnerPriceList1.getPriceListSet().stream()).filter(priceList -> priceList.getIsActive() && (priceList.getApplicationBeginDate() == null || priceList.getApplicationBeginDate().compareTo(appBaseService.getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))) <= 0) && (priceList.getApplicationEndDate() == null || priceList.getApplicationEndDate().compareTo(appBaseService.getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))) >= 0)).collect(Collectors.toList());
return "self.id IN (" + StringTool.getIdListString(priceLists) + ")";
}
use of com.axelor.apps.base.db.PartnerPriceList in project axelor-open-suite by axelor.
the class PartnerServiceImpl method getSalePriceList.
/**
* Search for the sale price list for the current date in the partner.
*
* @param partner
* @return the sale price list for the partner null if no active price list has been found
*/
@Override
public PriceList getSalePriceList(Partner partner) {
PartnerPriceList partnerPriceList = partner.getSalePartnerPriceList();
if (partnerPriceList == null) {
return null;
}
Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
if (priceListSet == null) {
return null;
}
LocalDate today = Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
List<PriceList> candidatePriceListList = new ArrayList<>();
for (PriceList priceList : priceListSet) {
LocalDate beginDate = priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN;
LocalDate endDate = priceList.getApplicationEndDate() != null ? priceList.getApplicationEndDate() : LocalDate.MAX;
if (beginDate.compareTo(today) <= 0 && today.compareTo(endDate) <= 0) {
candidatePriceListList.add(priceList);
}
}
// if we found multiple price list, then the user will have to select one
if (candidatePriceListList.size() == 1) {
return candidatePriceListList.get(0);
} else {
return null;
}
}
Aggregations