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