use of com.axelor.apps.production.db.ProdProcess in project axelor-open-suite by axelor.
the class ProdProcessController method changeProdProcessListOutsourcing.
public void changeProdProcessListOutsourcing(ActionRequest request, ActionResponse response) throws AxelorException {
ProdProcess prodProcess = request.getContext().asType(ProdProcess.class);
if (prodProcess.getProdProcessLineList() != null) {
Beans.get(ProdProcessService.class).changeProdProcessListOutsourcing(prodProcess);
}
response.setValue("prodProcessLineList", prodProcess.getProdProcessLineList());
response.setHidden("prodProcessLineList.outsourcing", !prodProcess.getOutsourcing());
if (!prodProcess.getOutsourcing()) {
response.setValue("generatePurchaseOrderOnMoPlanning", false);
response.setValue("subcontractors", null);
response.setValue("outsourcingStockLocation", null);
}
}
use of com.axelor.apps.production.db.ProdProcess in project axelor-open-suite by axelor.
the class ProdProcessController method generateNewVersion.
public void generateNewVersion(ActionRequest request, ActionResponse response) {
ProdProcess prodProcess = Beans.get(ProdProcessRepository.class).find(request.getContext().asType(ProdProcess.class).getId());
ProdProcess copy = Beans.get(ProdProcessService.class).generateNewVersion(prodProcess);
response.setView(ActionView.define("Production process").model(ProdProcess.class.getName()).add("form", "prod-process-form").add("grid", "prod-process-grid").param("search-filters", "prod-process-filters").context("_showRecord", String.valueOf(copy.getId())).map());
}
use of com.axelor.apps.production.db.ProdProcess in project axelor-open-suite by axelor.
the class ProdProcessService method getLatestProdProcessVersion.
public int getLatestProdProcessVersion(ProdProcess prodProcess, int latestVersion, boolean deep) {
List<ProdProcess> prodProcessSet = Lists.newArrayList();
ProdProcess up = prodProcess;
Long previousId = Long.valueOf(0);
do {
prodProcessSet = prodProcessRepo.all().filter("self.originalProdProcess = :origin AND self.id != :id").bind("origin", up).bind("id", previousId).order("-versionNumber").fetch();
if (!prodProcessSet.isEmpty()) {
latestVersion = (prodProcessSet.get(0).getVersionNumber() > latestVersion) ? prodProcessSet.get(0).getVersionNumber() : latestVersion;
for (ProdProcess prodProcessIterator : prodProcessSet) {
int search = this.getLatestProdProcessVersion(prodProcessIterator, latestVersion, false);
latestVersion = (search > latestVersion) ? search : latestVersion;
}
}
previousId = up.getId();
up = up.getOriginalProdProcess();
} while (up != null && deep);
return latestVersion;
}
use of com.axelor.apps.production.db.ProdProcess in project axelor-open-suite by axelor.
the class ConfiguratorBomServiceImpl method generateBillOfMaterial.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<BillOfMaterial> generateBillOfMaterial(ConfiguratorBOM configuratorBOM, JsonContext attributes, int level, Product generatedProduct) throws AxelorException {
level++;
if (level > MAX_LEVEL) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_TOO_MANY_CALLS));
}
String name;
Product product;
BigDecimal qty;
Unit unit;
ProdProcess prodProcess;
if (!checkConditions(configuratorBOM, attributes)) {
return Optional.empty();
}
if (configuratorBOM.getDefNameAsFormula()) {
name = (String) configuratorService.computeFormula(configuratorBOM.getNameFormula(), attributes);
} else {
name = configuratorBOM.getName();
}
if (configuratorBOM.getDefProductFromConfigurator()) {
if (generatedProduct == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_GENERATED_PRODUCT_NULL));
}
product = generatedProduct;
} else if (configuratorBOM.getDefProductAsFormula()) {
product = (Product) configuratorService.computeFormula(configuratorBOM.getProductFormula(), attributes);
if (product == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FORMULA_PRODUCT_NULL));
}
product = Beans.get(ProductRepository.class).find(product.getId());
} else {
if (configuratorBOM.getProduct() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FILLED_PRODUCT_NULL));
}
product = configuratorBOM.getProduct();
}
if (configuratorBOM.getDefQtyAsFormula()) {
qty = new BigDecimal(configuratorService.computeFormula(configuratorBOM.getQtyFormula(), attributes).toString());
} else {
qty = configuratorBOM.getQty();
}
if (configuratorBOM.getDefUnitAsFormula()) {
unit = (Unit) configuratorService.computeFormula(configuratorBOM.getUnitFormula(), attributes);
if (unit != null) {
unit = Beans.get(UnitRepository.class).find(unit.getId());
}
} else {
unit = configuratorBOM.getUnit();
}
if (configuratorBOM.getDefProdProcessAsFormula()) {
prodProcess = (ProdProcess) configuratorService.computeFormula(configuratorBOM.getProdProcessFormula(), attributes);
if (prodProcess != null) {
prodProcess = Beans.get(ProdProcessRepository.class).find(prodProcess.getId());
}
} else if (configuratorBOM.getDefProdProcessAsConfigurator()) {
prodProcess = confProdProcessService.generateProdProcessService(configuratorBOM.getConfiguratorProdProcess(), attributes, product);
} else {
prodProcess = configuratorBOM.getProdProcess();
}
BillOfMaterial billOfMaterial = new BillOfMaterial();
billOfMaterial.setCompany(configuratorBOM.getCompany());
billOfMaterial.setName(name);
billOfMaterial.setProduct(product);
billOfMaterial.setQty(qty);
billOfMaterial.setUnit(unit);
billOfMaterial.setProdProcess(prodProcess);
billOfMaterial.setStatusSelect(configuratorBOM.getStatusSelect());
billOfMaterial.setDefineSubBillOfMaterial(configuratorBOM.getDefineSubBillOfMaterial());
if (configuratorBOM.getConfiguratorBomList() != null) {
for (ConfiguratorBOM confBomChild : configuratorBOM.getConfiguratorBomList()) {
generateBillOfMaterial(confBomChild, attributes, level, generatedProduct).ifPresent(billOfMaterial::addBillOfMaterialSetItem);
}
}
billOfMaterial = billOfMaterialRepository.save(billOfMaterial);
configuratorBOM.setBillOfMaterialId(billOfMaterial.getId());
configuratorBOMRepo.save(configuratorBOM);
return Optional.of(billOfMaterial);
}
use of com.axelor.apps.production.db.ProdProcess in project axelor-open-suite by axelor.
the class ProdProcessController method checkOriginalProductionProcess.
public void checkOriginalProductionProcess(ActionRequest request, ActionResponse response) {
ProdProcessRepository prodProcessRepository = Beans.get(ProdProcessRepository.class);
ProdProcess prodProcess = prodProcessRepository.find(request.getContext().asType(ProdProcess.class).getId());
List<ProdProcess> prodProcessSet = Lists.newArrayList();
prodProcessSet = prodProcessRepository.all().filter("self.originalProdProcess = :origin").bind("origin", prodProcess).fetch();
String message;
if (!prodProcessSet.isEmpty()) {
String existingVersions = "";
for (ProdProcess prodProcessVersion : prodProcessSet) {
existingVersions += "<li>" + prodProcessVersion.getFullName() + "</li>";
}
message = String.format(I18n.get("This production process already has the following versions : <br/><ul> %s </ul>And these versions may also have ones. Do you still wish to create a new one ?"), existingVersions);
} else {
message = I18n.get("Do you really wish to create a new version of this production process ?");
}
response.setAlert(message);
}
Aggregations