use of com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository in project axelor-open-suite by axelor.
the class StockLocationSaveService method removeForbiddenDefaultStockLocation.
/**
* Remove default stock locations in partner that are not linked with this stock location anymore.
*
* @param defaultStockLocation
*/
@Transactional
public void removeForbiddenDefaultStockLocation(StockLocation defaultStockLocation) {
Partner currentPartner = defaultStockLocation.getPartner();
Company currentCompany = defaultStockLocation.getCompany();
Long partnerId = currentPartner != null ? currentPartner.getId() : 0L;
Long companyId = currentCompany != null ? currentCompany.getId() : 0L;
PartnerStockSettingsRepository partnerStockSettingsRepo = Beans.get(PartnerStockSettingsRepository.class);
List<PartnerStockSettings> partnerStockSettingsToRemove = partnerStockSettingsRepo.all().filter("(self.partner.id != :partnerId OR self.company.id != :companyId)" + " AND (self.defaultStockLocation.id = :stockLocationId)").bind("partnerId", partnerId).bind("companyId", companyId).bind("stockLocationId", defaultStockLocation.getId()).fetch();
for (PartnerStockSettings partnerStockSettings : partnerStockSettingsToRemove) {
Partner partnerToClean = partnerStockSettings.getPartner();
partnerToClean.removePartnerStockSettingsListItem(partnerStockSettings);
}
}
Aggregations