Search in sources :

Example 81 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class InvoicingProjectService method createInvoiceLine.

public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, int priority) throws AxelorException {
    Product product = purchaseOrderLine.getProduct();
    InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), priority, false, null, purchaseOrderLine, null) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product)

Example 82 with Product

use of com.axelor.apps.base.db.Product 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));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Project(com.axelor.apps.project.db.Project) ZonedDateTime(java.time.ZonedDateTime) Map(java.util.Map) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Example 83 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProjectGeneratorFactoryPhase method fill.

@Override
@Transactional
public ActionViewBuilder fill(Project project, SaleOrder saleOrder, LocalDateTime startDate) throws AxelorException {
    List<Project> projects = new ArrayList<>();
    projectRepository.save(project);
    for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
        Product product = saleOrderLine.getProduct();
        if (product != null && ProductRepository.PRODUCT_TYPE_SERVICE.equals(product.getProductTypeSelect()) && saleOrderLine.getSaleSupplySelect() == SaleOrderLineRepository.SALE_SUPPLY_PRODUCE) {
            Project phase = projectBusinessService.generatePhaseProject(saleOrderLine, project);
            phase.setFromDate(startDate);
            saleOrderLineRepository.save(saleOrderLine);
            projects.add(phase);
            if (!CollectionUtils.isEmpty(product.getTaskTemplateSet())) {
                productTaskTemplateService.convert(product.getTaskTemplateSet().stream().filter(template -> Objects.isNull(template.getParentTaskTemplate())).collect(Collectors.toList()), phase, null, startDate, saleOrderLine.getQty(), saleOrderLine);
            }
        }
    }
    return ActionView.define(String.format("Project%s generated", (projects.size() > 1 ? "s" : ""))).model(Project.class.getName()).add("grid", "project-grid").add("form", "project-form").param("search-filters", "project-filters").domain(String.format("self.id in (%s)", StringTool.getIdListString(projects)));
}
Also used : Project(com.axelor.apps.project.db.Project) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 84 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class MrpServiceProductionImpl method assignProductLevel.

/**
 * Update the level of Bill of materials. The highest for each product (0: product with parent, 1:
 * product with a parent, 2: product with a parent that have a parent, ...)
 *
 * @param billOfMaterial
 * @param level
 */
protected void assignProductLevel(BillOfMaterial billOfMaterial, int level) throws AxelorException {
    if (level > 100) {
        if (billOfMaterial == null || billOfMaterial.getProduct() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MRP_BOM_LEVEL_TOO_HIGH));
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MRP_BOM_LEVEL_TOO_HIGH_PRODUCT), billOfMaterial.getProduct().getFullName());
        }
    }
    Product product = billOfMaterial.getProduct();
    log.debug("Add product: {} for the level : {} ", product.getFullName(), level);
    this.productMap.put(product.getId(), this.getMaxLevel(product, level));
    level = level + 1;
    if (billOfMaterial.getBillOfMaterialSet() != null && !billOfMaterial.getBillOfMaterialSet().isEmpty()) {
        for (BillOfMaterial subBillOfMaterial : billOfMaterial.getBillOfMaterialSet()) {
            Product subProduct = subBillOfMaterial.getProduct();
            if (this.isMrpProduct(subProduct)) {
                this.assignProductLevel(subBillOfMaterial, level);
                if (subProduct.getDefaultBillOfMaterial() != null) {
                    this.assignProductLevel(subProduct.getDefaultBillOfMaterial(), level);
                }
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct)

Example 85 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProdProcessService method validateProdProcess.

public void validateProdProcess(ProdProcess prodProcess, BillOfMaterial bom) throws AxelorException {
    Map<Product, BigDecimal> bomMap = new HashMap<Product, BigDecimal>();
    Set<BillOfMaterial> setBoM = MoreObjects.firstNonNull(bom.getBillOfMaterialSet(), Collections.emptySet());
    for (BillOfMaterial bomIt : setBoM) {
        bomMap.put(bomIt.getProduct(), bomIt.getQty());
    }
    List<ProdProcessLine> listPPL = MoreObjects.firstNonNull(prodProcess.getProdProcessLineList(), Collections.emptyList());
    for (ProdProcessLine prodProcessLine : listPPL) {
        List<ProdProduct> listPP = MoreObjects.firstNonNull(prodProcessLine.getToConsumeProdProductList(), Collections.emptyList());
        for (ProdProduct prodProduct : listPP) {
            if (!bomMap.containsKey(prodProduct.getProduct())) {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PROD_PROCESS_USELESS_PRODUCT), prodProduct.getProduct().getName());
            }
            bomMap.put(prodProduct.getProduct(), bomMap.get(prodProduct.getProduct()).subtract(prodProduct.getQty()));
        }
    }
    Set<Product> keyList = bomMap.keySet();
    Map<Product, BigDecimal> copyMap = new HashMap<Product, BigDecimal>();
    List<String> nameProductList = new ArrayList<String>();
    for (Product product : keyList) {
        if (bomMap.get(product).compareTo(BigDecimal.ZERO) > 0) {
            copyMap.put(product, bomMap.get(product));
            nameProductList.add(product.getName());
        }
    }
    if (!copyMap.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PROD_PROCESS_MISS_PRODUCT), Joiner.on(",").join(nameProductList));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16