Search in sources :

Example 1 with CostSheet

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

the class UnitCostCalculationServiceImpl method calculationProductProcess.

@Transactional(rollbackOn = { Exception.class })
protected void calculationProductProcess(UnitCostCalculation unitCostCalculation, Product product) throws AxelorException {
    int level = this.productMap.get(product.getId()).intValue();
    log.debug("Unit cost price calculation for product : {}, level : {}", product.getCode(), level);
    int origin = unitCostCalculation.getAllBomLevels() ? CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION : CostSheetService.ORIGIN_BILL_OF_MATERIAL;
    BillOfMaterial billOfMaterial = product.getDefaultBillOfMaterial();
    CostSheet costSheet = costSheetService.computeCostPrice(billOfMaterial, origin, unitCostCalculation);
    UnitCostCalcLine unitCostCalcLine = unitCostCalcLineService.createUnitCostCalcLine(product, billOfMaterial.getCompany(), level, costSheet);
    unitCostCalculation.addUnitCostCalcLineListItem(unitCostCalcLine);
    unitCostCalculationRepository.save(unitCostCalculation);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) CostSheet(com.axelor.apps.production.db.CostSheet) Transactional(com.google.inject.persist.Transactional)

Example 2 with CostSheet

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

the class CostSheetServiceImpl method init.

protected void init() {
    AppProduction appProduction = appProductionService.getAppProduction();
    this.hourUnit = appProductionService.getAppBase().getUnitHours();
    this.cycleUnit = appProduction.getCycleUnit();
    this.manageResidualProductOnBom = appProduction.getManageResidualProductOnBom();
    costSheet = new CostSheet();
}
Also used : AppProduction(com.axelor.apps.base.db.AppProduction) CostSheet(com.axelor.apps.production.db.CostSheet)

Example 3 with CostSheet

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

the class ManufOrderController method computeCostPrice.

/**
 * Called from manuf order form, on clicking "compute cost price" button. Call {@link
 * CostSheetService#computeCostPrice(ManufOrder, int, LocalDate)}.
 *
 * @param request
 * @param response
 */
public void computeCostPrice(ActionRequest request, ActionResponse response) {
    try {
        ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
        manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
        CostSheet costSheet = Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_WORK_IN_PROGRESS, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
        response.setView(ActionView.define(I18n.get("Cost sheet")).model(CostSheet.class.getName()).param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").add("grid", "cost-sheet-bill-of-material-grid").add("form", "cost-sheet-bill-of-material-form").context("_showRecord", String.valueOf(costSheet.getId())).map());
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) CostSheet(com.axelor.apps.production.db.CostSheet) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 4 with CostSheet

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

the class CostSheetServiceImpl method computeCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public CostSheet computeCostPrice(ManufOrder manufOrder, int calculationTypeSelect, LocalDate calculationDate) throws AxelorException {
    this.init();
    List<CostSheet> costSheetList = manufOrder.getCostSheetList();
    LocalDate previousCostSheetDate = null;
    for (CostSheet costSheet : costSheetList) {
        if ((costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_END_OF_PRODUCTION || costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION) && costSheet.getCalculationDate() != null) {
            if (previousCostSheetDate == null) {
                previousCostSheetDate = costSheet.getCalculationDate();
            } else if (costSheet.getCalculationDate().isAfter(previousCostSheetDate)) {
                previousCostSheetDate = costSheet.getCalculationDate();
            }
        }
    }
    manufOrder.addCostSheetListItem(costSheet);
    costSheet.setCalculationTypeSelect(calculationTypeSelect);
    costSheet.setCalculationDate(calculationDate != null ? calculationDate : Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
    BigDecimal producedQty = computeTotalProducedQty(manufOrder.getProduct(), manufOrder.getProducedStockMoveLineList(), costSheet.getCalculationDate(), previousCostSheetDate, costSheet.getCalculationTypeSelect());
    CostSheetLine producedCostSheetLine = costSheetLineService.createProducedProductCostSheetLine(manufOrder.getProduct(), manufOrder.getUnit(), producedQty);
    costSheet.addCostSheetLineListItem(producedCostSheetLine);
    Company company = manufOrder.getCompany();
    if (company != null && company.getCurrency() != null) {
        costSheet.setCurrency(company.getCurrency());
    }
    BigDecimal totalToProduceQty = getTotalToProduceQty(manufOrder);
    BigDecimal ratio = BigDecimal.ZERO;
    if (totalToProduceQty.compareTo(BigDecimal.ZERO) != 0) {
        ratio = producedQty.divide(totalToProduceQty, 5, RoundingMode.HALF_UP);
    }
    costSheet.setManufOrderProducedRatio(ratio);
    this.computeRealCostPrice(manufOrder, 0, producedCostSheetLine, previousCostSheetDate);
    this.computeRealResidualProduct(manufOrder);
    this.computeCostPrice(costSheet);
    manufOrder.setCostPrice(costSheet.getCostPrice());
    Beans.get(ManufOrderRepository.class).save(manufOrder);
    return costSheet;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) LocalDate(java.time.LocalDate) CostSheet(com.axelor.apps.production.db.CostSheet) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 5 with CostSheet

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

the class BillOfMaterialController method computeCostPrice.

public void computeCostPrice(ActionRequest request, ActionResponse response) throws AxelorException {
    BillOfMaterial billOfMaterial = request.getContext().asType(BillOfMaterial.class);
    CostSheet costSheet = Beans.get(CostSheetService.class).computeCostPrice(Beans.get(BillOfMaterialRepository.class).find(billOfMaterial.getId()), CostSheetService.ORIGIN_BILL_OF_MATERIAL, null);
    response.setView(ActionView.define(String.format(I18n.get("Cost sheet - %s"), billOfMaterial.getName())).model(CostSheet.class.getName()).param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").add("grid", "cost-sheet-bill-of-material-grid").add("form", "cost-sheet-bill-of-material-form").context("_showRecord", String.valueOf(costSheet.getId())).map());
    response.setReload(true);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) CostSheet(com.axelor.apps.production.db.CostSheet)

Aggregations

CostSheet (com.axelor.apps.production.db.CostSheet)7 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)2 CostSheetService (com.axelor.apps.production.service.costsheet.CostSheetService)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 AppProduction (com.axelor.apps.base.db.AppProduction)1 Company (com.axelor.apps.base.db.Company)1 Product (com.axelor.apps.base.db.Product)1 Unit (com.axelor.apps.base.db.Unit)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 CostSheetLine (com.axelor.apps.production.db.CostSheetLine)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)1 UnitCostCalcLine (com.axelor.apps.production.db.UnitCostCalcLine)1 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)1 AxelorException (com.axelor.exception.AxelorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1