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);
}
}
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);
}
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));
}
}
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);
}
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;
}
Aggregations