Search in sources :

Example 1 with StockConfig

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

the class LogisticalFormStockRepository method save.

@Override
public LogisticalForm save(LogisticalForm logisticalForm) {
    try {
        Company company = logisticalForm.getCompany();
        if (company != null) {
            if (Strings.isNullOrEmpty(logisticalForm.getDeliveryNumberSeq())) {
                String sequenceNumber = Beans.get(SequenceService.class).getSequenceNumber("logisticalForm", logisticalForm.getCompany());
                if (Strings.isNullOrEmpty(sequenceNumber)) {
                    throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_SEQUENCE), logisticalForm.getCompany().getName());
                }
                logisticalForm.setDeliveryNumberSeq(sequenceNumber);
            }
            if (!logisticalForm.getIsEmailSent()) {
                StockConfig stockConfig = Beans.get(StockConfigService.class).getStockConfig(company);
                if (stockConfig.getLogisticalFormAutomaticEmail()) {
                    Template template = stockConfig.getLogisticalFormMessageTemplate();
                    if (template == null) {
                        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_TEMPLATE), logisticalForm);
                    }
                    Beans.get(TemplateMessageService.class).generateAndSendMessage(logisticalForm, template);
                    logisticalForm.setIsEmailSent(true);
                }
            }
        }
        return super.save(logisticalForm);
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockConfig(com.axelor.apps.stock.db.StockConfig) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) PersistenceException(javax.persistence.PersistenceException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException) Template(com.axelor.apps.message.db.Template)

Example 2 with StockConfig

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

the class ProductStockRepository method save.

public Product save(Product product) {
    WeightedAveragePriceService weightedAveragePriceService = Beans.get(WeightedAveragePriceService.class);
    Set<MetaField> specificProductFieldSet = appBaseService.getAppBase().getCompanySpecificProductFieldsSet();
    if (!specificProductFieldSet.isEmpty() && appBaseService.getAppBase().getEnableMultiCompany()) {
        ArrayList<Company> productCompanyList = new ArrayList<>();
        if (product.getProductCompanyList() != null) {
            for (ProductCompany productCompany : product.getProductCompanyList()) {
                productCompanyList.add(productCompany.getCompany());
            }
        }
        Mapper mapper = Mapper.of(Product.class);
        List<StockConfig> stockConfigList = Beans.get(StockConfigRepository.class).all().fetch();
        for (StockConfig stockConfig : stockConfigList) {
            if (stockConfig.getCompany() != null && !productCompanyList.contains(stockConfig.getCompany()) && stockConfig.getReceiptDefaultStockLocation() != null && (stockConfig.getCompany().getArchived() == null || !stockConfig.getCompany().getArchived())) {
                ProductCompany productCompany = new ProductCompany();
                for (MetaField specificField : specificProductFieldSet) {
                    mapper.set(productCompany, specificField.getName(), mapper.get(product, specificField.getName()));
                }
                // specific case for avgPrice per company
                productCompany.setAvgPrice(weightedAveragePriceService.computeAvgPriceForCompany(product, stockConfig.getCompany()));
                productCompany.setCompany(stockConfig.getCompany());
                productCompany.setProduct(product);
                product.addProductCompanyListItem(productCompany);
            }
        }
    }
    return super.save(product);
}
Also used : Mapper(com.axelor.db.mapper.Mapper) Company(com.axelor.apps.base.db.Company) ProductCompany(com.axelor.apps.base.db.ProductCompany) StockConfig(com.axelor.apps.stock.db.StockConfig) MetaField(com.axelor.meta.db.MetaField) WeightedAveragePriceService(com.axelor.apps.stock.service.WeightedAveragePriceService) ArrayList(java.util.ArrayList) ProductCompany(com.axelor.apps.base.db.ProductCompany)

Example 3 with StockConfig

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

the class StockMoveServiceImpl method computeMasses.

private void computeMasses(StockMove stockMove) throws AxelorException {
    StockConfig stockConfig = stockMove.getCompany().getStockConfig();
    Unit endUnit = stockConfig != null ? stockConfig.getCustomsMassUnit() : null;
    boolean massesRequiredForStockMove = false;
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        return;
    }
    UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        boolean massesRequiredForStockMoveLine = stockMoveLineService.checkMassesRequired(stockMove, stockMoveLine);
        if (product == null || !ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect())) {
            continue;
        }
        BigDecimal netMass = stockMoveLine.getNetMass();
        if (netMass.signum() == 0) {
            Unit startUnit = product.getMassUnit();
            if (startUnit != null && endUnit != null) {
                netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), product.getNetMass().scale(), null);
                stockMoveLine.setNetMass(netMass);
            }
        }
        if (netMass.signum() != 0) {
            BigDecimal totalNetMass = netMass.multiply(stockMoveLine.getRealQty());
            stockMoveLine.setTotalNetMass(totalNetMass);
        } else if (massesRequiredForStockMoveLine) {
            throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_18));
        }
        if (!massesRequiredForStockMove && massesRequiredForStockMoveLine) {
            massesRequiredForStockMove = true;
        }
    }
    if (massesRequiredForStockMove && endUnit == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_17));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 4 with StockConfig

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

the class OperationOrderStockMoveService method _createToConsumeStockMove.

protected StockMove _createToConsumeStockMove(OperationOrder operationOrder, Company company) throws AxelorException {
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
    StockLocation fromStockLocation;
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    if (operationOrder.getManufOrder().getIsConsProOnOperation() && prodProcessLine != null && prodProcessLine.getStockLocation() != null) {
        fromStockLocation = prodProcessLine.getStockLocation();
    } else if (!operationOrder.getManufOrder().getIsConsProOnOperation() && prodProcessLine != null && prodProcessLine.getProdProcess() != null && prodProcessLine.getProdProcess().getStockLocation() != null) {
        fromStockLocation = prodProcessLine.getProdProcess().getStockLocation();
    } else {
        fromStockLocation = stockConfigService.getComponentDefaultStockLocation(stockConfig);
    }
    return stockMoveService.createStockMove(null, null, company, fromStockLocation, virtualStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
}
Also used : StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine)

Example 5 with StockConfig

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

the class PurchaseOrderStockServiceImpl method getStartStockLocation.

protected StockLocation getStartStockLocation(PurchaseOrder purchaseOrder) throws AxelorException {
    Company company = purchaseOrder.getCompany();
    StockLocation startLocation = purchaseOrder.getFromStockLocation();
    if (startLocation == null) {
        startLocation = partnerStockSettingsService.getDefaultExternalStockLocation(purchaseOrder.getSupplierPartner(), company);
    }
    if (startLocation == null) {
        StockConfigService stockConfigService = Beans.get(StockConfigService.class);
        StockConfig stockConfig = stockConfigService.getStockConfig(company);
        startLocation = stockConfigService.getSupplierVirtualStockLocation(stockConfig);
    }
    if (startLocation == null) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PURCHASE_ORDER_1), company.getName());
    }
    return startLocation;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService)

Aggregations

StockConfig (com.axelor.apps.stock.db.StockConfig)16 StockLocation (com.axelor.apps.stock.db.StockLocation)8 Company (com.axelor.apps.base.db.Company)7 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)7 AxelorException (com.axelor.exception.AxelorException)7 StockMove (com.axelor.apps.stock.db.StockMove)6 StockConfigService (com.axelor.apps.stock.service.config.StockConfigService)6 Transactional (com.google.inject.persist.Transactional)5 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Product (com.axelor.apps.base.db.Product)2 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 ProdProduct (com.axelor.apps.production.db.ProdProduct)2 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)2 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)2 StockMoveService (com.axelor.apps.stock.service.StockMoveService)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2 List (java.util.List)2