Search in sources :

Example 26 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method createToConsumeProdProductList.

@Override
public void createToConsumeProdProductList(ManufOrder manufOrder) {
    BigDecimal manufOrderQty = manufOrder.getQty();
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    BigDecimal bomQty = billOfMaterial.getQty();
    if (billOfMaterial.getBillOfMaterialSet() != null) {
        for (BillOfMaterial billOfMaterialLine : getSortedBillsOfMaterials(billOfMaterial.getBillOfMaterialSet())) {
            if (!billOfMaterialLine.getHasNoManageStock()) {
                Product product = productVariantService.getProductVariant(manufOrder.getProduct(), billOfMaterialLine.getProduct());
                BigDecimal qty = computeToConsumeProdProductLineQuantity(bomQty, manufOrderQty, billOfMaterialLine.getQty());
                ProdProduct prodProduct = new ProdProduct(product, qty, billOfMaterialLine.getUnit());
                manufOrder.addToConsumeProdProductListItem(prodProduct);
                // id by order of creation
                prodProductRepo.persist(prodProduct);
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 27 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class CostSheetLineServiceImpl method createConsumedProductWasteCostSheetLine.

public CostSheetLine createConsumedProductWasteCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, BigDecimal wasteRate, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    Product parentProduct = parentCostSheetLine.getProduct();
    BigDecimal qty = consumptionQty.multiply(wasteRate).divide(new BigDecimal("100"), appBaseService.getNbDecimalDigitForQty(), BigDecimal.ROUND_HALF_UP);
    BigDecimal costPrice = null;
    switch(origin) {
        case CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION:
            BillOfMaterial componentDefaultBillOfMaterial = product.getDefaultBillOfMaterial();
            if (componentDefaultBillOfMaterial != null) {
                UnitCostCalcLine unitCostCalcLine = unitCostCalcLineServiceImpl.getUnitCostCalcLine(unitCostCalculation, product);
                if (unitCostCalcLine != null) {
                    costPrice = unitCostCalcLine.getComputedCost();
                    break;
                }
            }
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        default:
            costPrice = BigDecimal.ZERO;
    }
    costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product).multiply(qty);
    return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, qty, costPrice.setScale(appProductionService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP), product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, unit, null, parentCostSheetLine);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Example 28 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class CostSheetLineServiceImpl method createConsumedProductCostSheetLine.

public CostSheetLine createConsumedProductCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    Product parentProduct = parentCostSheetLine.getProduct();
    BigDecimal costPrice = null;
    switch(origin) {
        case CostSheetService.ORIGIN_MANUF_ORDER:
            costPrice = this.getComponentCostPrice(product, parentProduct.getManufOrderCompValuMethodSelect(), company);
            break;
        case CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION:
            BillOfMaterial componentDefaultBillOfMaterial = product.getDefaultBillOfMaterial();
            if (componentDefaultBillOfMaterial != null) {
                UnitCostCalcLine unitCostCalcLine = unitCostCalcLineServiceImpl.getUnitCostCalcLine(unitCostCalculation, product);
                if (unitCostCalcLine != null) {
                    costPrice = unitCostCalcLine.getComputedCost();
                    break;
                }
            }
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        // from its bill of materials
        case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        default:
            costPrice = BigDecimal.ZERO;
    }
    consumptionQty = consumptionQty.setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
    costPrice = costPrice.multiply(consumptionQty);
    costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product);
    List<CostSheetLine> costSheetLineList = parentCostSheetLine.getCostSheetLineList() != null ? parentCostSheetLine.getCostSheetLineList() : new ArrayList<CostSheetLine>();
    for (CostSheetLine costSheetLine : costSheetLineList) {
        if (product.equals(costSheetLine.getProduct()) && unit.equals(costSheetLine.getUnit())) {
            BigDecimal qty = costSheetLine.getConsumptionQty().add(consumptionQty);
            costSheetLine.setConsumptionQty(qty);
            costSheetLine.setCostPrice(costPrice.add(costSheetLine.getCostPrice()).setScale(appProductionService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP));
            return costSheetLine;
        }
    }
    return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, consumptionQty, costPrice, product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, unit, null, parentCostSheetLine);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) CostSheetLine(com.axelor.apps.production.db.CostSheetLine) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Example 29 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ManufOrderController method generateMultiLevelManufOrder.

/**
 * Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
    try {
        Long moId = Long.valueOf(request.getContext().get("id").toString());
        ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
        ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
        List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
        if (prodProductList.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
        }
        List<Product> selectedProductList = new ArrayList<>();
        for (ProdProduct prod : prodProductList) {
            if (selectedProductList.contains(prod.getProduct())) {
                throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
            }
            selectedProductList.add(prod.getProduct());
        }
        List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
        response.setCanClose(true);
        response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 30 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method computeTotalProducedQty.

protected BigDecimal computeTotalProducedQty(Product producedProduct, List<StockMoveLine> producedStockMoveLineList, LocalDate calculationDate, LocalDate previousCostSheetDate, int calculationTypeSelect) throws AxelorException {
    BigDecimal totalQty = BigDecimal.ZERO;
    Map<List<Object>, BigDecimal> producedStockMoveLinePerProductAndUnit = getTotalQtyPerProductAndUnit(producedStockMoveLineList, calculationDate, previousCostSheetDate, calculationTypeSelect);
    for (List<Object> keys : producedStockMoveLinePerProductAndUnit.keySet()) {
        Iterator<Object> iterator = keys.iterator();
        Product product = (Product) iterator.next();
        Unit unit = (Unit) iterator.next();
        BigDecimal realQty = producedStockMoveLinePerProductAndUnit.get(keys);
        if (product == null || !product.equals(producedProduct)) {
            continue;
        }
        totalQty = totalQty.add(unitConversionService.convert(unit, costSheet.getManufOrder().getUnit(), realQty, realQty.scale(), product));
    }
    return totalQty;
}
Also used : ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ArrayList(java.util.ArrayList) List(java.util.List) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16