use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method createPurchaseOrderLineProduction.
private void createPurchaseOrderLineProduction(OperationOrder operationOrder, PurchaseOrder purchaseOrder) throws AxelorException {
UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
PurchaseOrderLine purchaseOrderLine;
BigDecimal quantity = BigDecimal.ONE;
Unit startUnit = Beans.get(UnitRepository.class).all().filter("self.name = 'Hour' AND self.unitTypeSelect = 3").fetchOne();
for (ProdHumanResource humanResource : operationOrder.getProdHumanResourceList()) {
Product product = humanResource.getProduct();
Unit purchaseUnit = product.getPurchasesUnit();
if (purchaseUnit != null) {
quantity = unitConversionService.convert(startUnit, purchaseUnit, new BigDecimal(humanResource.getDuration() / 3600), 0, humanResource.getProduct());
}
purchaseOrderLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, null, null, quantity, purchaseUnit);
purchaseOrder.getPurchaseOrderLineList().add(purchaseOrderLine);
}
}
Aggregations