Search in sources :

Example 6 with BillOfMaterial

use of com.axelor.apps.production.db.BillOfMaterial 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 7 with BillOfMaterial

use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method _computeToConsumeProduct.

protected void _computeToConsumeProduct(Company company, BillOfMaterial billOfMaterial, int bomLevel, CostSheetLine parentCostSheetLine, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    if (billOfMaterial.getBillOfMaterialSet() != null) {
        for (BillOfMaterial billOfMaterialLine : billOfMaterial.getBillOfMaterialSet()) {
            Product product = billOfMaterialLine.getProduct();
            if (product != null) {
                CostSheetLine costSheetLine = costSheetLineService.createConsumedProductCostSheetLine(company, product, billOfMaterialLine.getUnit(), bomLevel, parentCostSheetLine, billOfMaterialLine.getQty(), origin, unitCostCalculation);
                BigDecimal wasteRate = billOfMaterialLine.getWasteRate();
                if (wasteRate != null && wasteRate.compareTo(BigDecimal.ZERO) > 0) {
                    costSheetLineService.createConsumedProductWasteCostSheetLine(company, product, billOfMaterialLine.getUnit(), bomLevel, parentCostSheetLine, billOfMaterialLine.getQty(), wasteRate, origin, unitCostCalculation);
                }
                if (billOfMaterialLine.getDefineSubBillOfMaterial()) {
                    this._computeCostPrice(company, billOfMaterialLine, bomLevel, costSheetLine, origin, unitCostCalculation);
                }
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) CostSheetLine(com.axelor.apps.production.db.CostSheetLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) BigDecimal(java.math.BigDecimal)

Example 8 with BillOfMaterial

use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.

the class SaleOrderLineController method customizeBillOfMaterial.

public void customizeBillOfMaterial(ActionRequest request, ActionResponse response) {
    try {
        SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
        BillOfMaterial copyBillOfMaterial = Beans.get(BillOfMaterialService.class).customizeBillOfMaterial(saleOrderLine);
        if (copyBillOfMaterial != null) {
            response.setValue("billOfMaterial", copyBillOfMaterial);
            response.setFlash(I18n.get(IExceptionMessage.SALE_ORDER_LINE_1));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) BillOfMaterialService(com.axelor.apps.production.service.BillOfMaterialService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 9 with BillOfMaterial

use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.

the class BillOfMaterialController method updateProductCostPrice.

public void updateProductCostPrice(ActionRequest request, ActionResponse response) throws AxelorException {
    BillOfMaterial billOfMaterial = request.getContext().asType(BillOfMaterial.class);
    Beans.get(BillOfMaterialService.class).updateProductCostPrice(Beans.get(BillOfMaterialRepository.class).find(billOfMaterial.getId()));
    response.setReload(true);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) BillOfMaterialService(com.axelor.apps.production.service.BillOfMaterialService)

Example 10 with BillOfMaterial

use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.

the class ProductionOrderWizardServiceBusinessImpl method validate.

@Override
@SuppressWarnings("unchecked")
public Long validate(Context context) throws AxelorException {
    AppProductionService appProductionService = Beans.get(AppProductionService.class);
    if (!appProductionService.isApp("production") || !appProductionService.getAppProduction().getManageBusinessProduction()) {
        return super.validate(context);
    }
    Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial");
    BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue());
    BigDecimal qty = new BigDecimal((String) context.get("qty"));
    Product product = null;
    if (context.get("product") != null) {
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        product = productRepo.find(((Integer) productContext.get("id")).longValue());
    } else {
        product = billOfMaterial.getProduct();
    }
    ZonedDateTime startDateT, endDateT = null;
    if (context.containsKey("_startDate") && context.get("_startDate") != null) {
        startDateT = ZonedDateTime.parse(context.get("_startDate").toString(), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
    } else {
        startDateT = appProductionService.getTodayDateTime();
    }
    if (context.containsKey("_endDate") && context.get("_endDate") != null) {
        endDateT = ZonedDateTime.parse(context.get("_endDate").toString(), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
    }
    Project project = null;
    if (context.get("business_id") != null) {
        project = Beans.get(ProjectRepository.class).find(((Integer) context.get("business_id")).longValue());
    }
    ProductionOrder productionOrder = productionOrderServiceBusinessImpl.generateProductionOrder(product, billOfMaterial, qty, project, startDateT.toLocalDateTime(), endDateT != null ? endDateT.toLocalDateTime() : null, null);
    if (productionOrder != null) {
        return productionOrder.getId();
    } else {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_2));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Project(com.axelor.apps.project.db.Project) ZonedDateTime(java.time.ZonedDateTime) Map(java.util.Map) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Aggregations

BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)36 Product (com.axelor.apps.base.db.Product)19 BigDecimal (java.math.BigDecimal)16 AxelorException (com.axelor.exception.AxelorException)15 Transactional (com.google.inject.persist.Transactional)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ArrayList (java.util.ArrayList)8 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)7 BillOfMaterialService (com.axelor.apps.production.service.BillOfMaterialService)7 Unit (com.axelor.apps.base.db.Unit)4 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)4 ProdProcess (com.axelor.apps.production.db.ProdProcess)4 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)4 ProductionOrder (com.axelor.apps.production.db.ProductionOrder)4 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)4 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 ManufOrder (com.axelor.apps.production.db.ManufOrder)3 UnitCostCalcLine (com.axelor.apps.production.db.UnitCostCalcLine)3 BillOfMaterialRepository (com.axelor.apps.production.db.repo.BillOfMaterialRepository)3