Search in sources :

Example 6 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService 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);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) ProdHumanResource(com.axelor.apps.production.db.ProdHumanResource) UnitRepository(com.axelor.apps.base.db.repo.UnitRepository) Product(com.axelor.apps.base.db.Product) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) ChronoUnit(java.time.temporal.ChronoUnit) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)6 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)6 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)4 Context (com.axelor.rpc.Context)4 Product (com.axelor.apps.base.db.Product)3 BigDecimal (java.math.BigDecimal)2 Unit (com.axelor.apps.base.db.Unit)1 UnitRepository (com.axelor.apps.base.db.repo.UnitRepository)1 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 ProdHumanResource (com.axelor.apps.production.db.ProdHumanResource)1 ChronoUnit (java.time.temporal.ChronoUnit)1