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