Search in sources :

Example 1 with PartnerStockSettingsRepository

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);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) PartnerStockSettingsRepository(com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerStockSettings (com.axelor.apps.stock.db.PartnerStockSettings)1 PartnerStockSettingsRepository (com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository)1 Transactional (com.google.inject.persist.Transactional)1