Search in sources :

Example 1 with StockMoveLineService

use of com.axelor.apps.stock.service.StockMoveLineService in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method generateWasteStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
    StockMove wasteStockMove = null;
    Company company = manufOrder.getCompany();
    if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
        return wasteStockMove;
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
    StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
    wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
    for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
        stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
    }
    stockMoveService.validate(wasteStockMove);
    manufOrder.setWasteStockMove(wasteStockMove);
    return wasteStockMove;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) Transactional(com.google.inject.persist.Transactional)

Aggregations

Company (com.axelor.apps.base.db.Company)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)1 OperationOrderStockMoveService (com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService)1 StockConfig (com.axelor.apps.stock.db.StockConfig)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)1 StockMoveService (com.axelor.apps.stock.service.StockMoveService)1 Transactional (com.google.inject.persist.Transactional)1