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