Search in sources :

Example 1 with PartnerStockSettings

use of com.axelor.apps.stock.db.PartnerStockSettings in project axelor-open-suite by axelor.

the class PartnerStockSettingsServiceImpl method createMailSettings.

@Override
@Transactional(rollbackOn = { Exception.class })
public PartnerStockSettings createMailSettings(Partner partner, Company company) throws AxelorException {
    PartnerStockSettings mailSettings = new PartnerStockSettings();
    mailSettings.setCompany(company);
    StockConfig stockConfig = Beans.get(StockConfigService.class).getStockConfig(company);
    mailSettings.setPlannedStockMoveAutomaticMail(stockConfig.getPlannedStockMoveAutomaticMail());
    mailSettings.setPlannedStockMoveMessageTemplate(stockConfig.getPlannedStockMoveMessageTemplate());
    mailSettings.setRealStockMoveAutomaticMail(stockConfig.getRealStockMoveAutomaticMail());
    mailSettings.setRealStockMoveMessageTemplate(stockConfig.getRealStockMoveMessageTemplate());
    partner.addPartnerStockSettingsListItem(mailSettings);
    return Beans.get(PartnerStockSettingsRepository.class).save(mailSettings);
}
Also used : PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) StockConfig(com.axelor.apps.stock.db.StockConfig) PartnerStockSettingsRepository(com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) Transactional(com.google.inject.persist.Transactional)

Example 2 with PartnerStockSettings

use of com.axelor.apps.stock.db.PartnerStockSettings in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method setDefaultAutoMailSettings.

/**
 * Set automatic mail configuration from the partner.
 *
 * @param stockMove
 */
protected void setDefaultAutoMailSettings(StockMove stockMove) throws AxelorException {
    Partner partner = stockMove.getPartner();
    Company company = stockMove.getCompany();
    PartnerStockSettings mailSettings = Beans.get(PartnerStockSettingsService.class).getOrCreateMailSettings(partner, company);
    stockMove.setRealStockMoveAutomaticMail(mailSettings.getRealStockMoveAutomaticMail());
    stockMove.setRealStockMoveMessageTemplate(mailSettings.getRealStockMoveMessageTemplate());
    stockMove.setPlannedStockMoveAutomaticMail(mailSettings.getPlannedStockMoveAutomaticMail());
    stockMove.setPlannedStockMoveMessageTemplate(mailSettings.getPlannedStockMoveMessageTemplate());
}
Also used : PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) Company(com.axelor.apps.base.db.Company) PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) Partner(com.axelor.apps.base.db.Partner)

Example 3 with PartnerStockSettings

use of com.axelor.apps.stock.db.PartnerStockSettings 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

PartnerStockSettings (com.axelor.apps.stock.db.PartnerStockSettings)3 Company (com.axelor.apps.base.db.Company)2 Partner (com.axelor.apps.base.db.Partner)2 PartnerStockSettingsRepository (com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository)2 Transactional (com.google.inject.persist.Transactional)2 StockConfig (com.axelor.apps.stock.db.StockConfig)1 PartnerStockSettingsService (com.axelor.apps.stock.service.PartnerStockSettingsService)1 StockConfigService (com.axelor.apps.stock.service.config.StockConfigService)1