Search in sources :

Example 76 with PurchaseOrderLine

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);
    }
}
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)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5