First commit (wating to add alerts in budget)
This commit is contained in:
@@ -24,15 +24,19 @@ import com.google.inject.persist.Transactional;
|
||||
|
||||
public interface QvmOperationService {
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException;
|
||||
@Transactional
|
||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException;
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createQualificationSeq(Company company) throws AxelorException;
|
||||
@Transactional
|
||||
public QvmOperation createQualificationSeq(Company company) throws AxelorException;
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createOperationSeq(Company company) throws AxelorException;
|
||||
@Transactional
|
||||
public QvmOperation createOperationSeq(Company company) throws AxelorException;
|
||||
|
||||
@Transactional
|
||||
public QvmOperation setMachine(QvmOperation operation) throws AxelorException;
|
||||
@Transactional
|
||||
public QvmOperation setMachine(QvmOperation operation) throws AxelorException;
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createNextOperation(QvmOperation operation, Long userId)
|
||||
throws AxelorException;
|
||||
}
|
||||
|
||||
@@ -21,84 +21,118 @@ import com.axelor.apps.base.db.Company;
|
||||
import com.axelor.apps.base.db.repo.SequenceRepository;
|
||||
import com.axelor.apps.base.service.administration.SequenceService;
|
||||
import com.axelor.apps.qvm.db.QvmOperation;
|
||||
import com.axelor.apps.qvm.db.repo.QvmOperationRepository;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
|
||||
public class QvmOperationServiceImpl implements QvmOperationService {
|
||||
|
||||
@Inject
|
||||
protected SequenceService sequenceService;
|
||||
@Inject protected SequenceService sequenceService;
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException {
|
||||
@Transactional
|
||||
public QvmOperation createCalibrationSeq(Company company) throws AxelorException {
|
||||
|
||||
QvmOperation calibration = new QvmOperation();
|
||||
calibration.setSerialNumber(this.getCalibrationSequence(company));
|
||||
QvmOperation calibration = new QvmOperation();
|
||||
calibration.setSerialNumber(this.getCalibrationSequence(company));
|
||||
|
||||
return calibration;
|
||||
return calibration;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createQualificationSeq(Company company) throws AxelorException {
|
||||
|
||||
QvmOperation qualification = new QvmOperation();
|
||||
qualification.setSerialNumber(this.getQualificationSequence(company));
|
||||
|
||||
return qualification;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createOperationSeq(Company company) throws AxelorException {
|
||||
|
||||
QvmOperation operation = new QvmOperation();
|
||||
operation.setSerialNumber(this.getOperationSequence(company));
|
||||
|
||||
return operation;
|
||||
}
|
||||
|
||||
public String getCalibrationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.CALIB_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Calibration Sequence is not defined"),
|
||||
company.getName());
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createQualificationSeq(Company company) throws AxelorException {
|
||||
|
||||
QvmOperation qualification = new QvmOperation();
|
||||
qualification.setSerialNumber(this.getQualificationSequence(company));
|
||||
|
||||
return qualification;
|
||||
public String getQualificationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.QUAL_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Qualification Sequence is not defined"),
|
||||
company.getName());
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public QvmOperation createOperationSeq(Company company) throws AxelorException {
|
||||
|
||||
QvmOperation operation = new QvmOperation();
|
||||
operation.setSerialNumber(this.getOperationSequence(company));
|
||||
|
||||
return operation;
|
||||
public String getOperationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.OP_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Operation Sequence is not defined"),
|
||||
company.getName());
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
public String getCalibrationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.CALIB_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Calibration Sequence is not defined"),
|
||||
company.getName());
|
||||
public QvmOperation setMachine(QvmOperation calibration) throws AxelorException {
|
||||
if (calibration.getMachineName() != null) {
|
||||
System.out.println("calibration.getMachineName : " + calibration.getMachineName());
|
||||
}
|
||||
return calibration;
|
||||
}
|
||||
|
||||
public QvmOperation createNextOperation(QvmOperation operation, Long userId) {
|
||||
QvmOperation nextOperation = Beans.get(QvmOperationRepository.class).copy(operation, true);
|
||||
if (operation != null) {
|
||||
try {
|
||||
nextOperation.setStatusSelect(1);
|
||||
nextOperation.setOperationOrigin(operation.getSerialNumber());
|
||||
nextOperation.setCreationType(2);
|
||||
nextOperation.setPastOperationDate(operation.getOperationDate());
|
||||
nextOperation.setOperationDate(operation.getOperationDueDate());
|
||||
if (operation.getOperationFrequency() == 1) {
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusYears(1));
|
||||
nextOperation.setCountdown(364);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
public String getQualificationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.QUAL_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Qualification Sequence is not defined"),
|
||||
company.getName());
|
||||
if (operation.getOperationFrequency() == 2) {
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(1));
|
||||
nextOperation.setCountdown(31);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
public String getOperationSequence(Company company) throws AxelorException {
|
||||
String seq = sequenceService.getSequenceNumber(SequenceRepository.OP_SEQ, company);
|
||||
if (seq == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get("Operation Sequence is not defined"),
|
||||
company.getName());
|
||||
if (operation.getOperationFrequency() == 3) {
|
||||
nextOperation.setOperationDueDate(operation.getOperationDueDate().plusMonths(6));
|
||||
nextOperation.setCountdown(183);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
public QvmOperation setMachine(QvmOperation calibration) throws AxelorException {
|
||||
if (calibration.getMachineName() != null) {
|
||||
System.out.println("calibration.getMachineName : " + calibration.getMachineName());
|
||||
}
|
||||
return calibration;
|
||||
System.out.println(
|
||||
"operation.getOperationFrequency : " + operation.getOperationFrequency());
|
||||
nextOperation.setSerialNumber(null);
|
||||
nextOperation.setCreationType(2);
|
||||
} catch (Exception exception) {
|
||||
System.out.println(exception);
|
||||
}
|
||||
}
|
||||
// Beans.get(QvmOperationRepository.class).save(nextOperation);
|
||||
return nextOperation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.axelor.apps.qvm.translation;
|
||||
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public interface ITranslation {
|
||||
|
||||
public static final String OPERATION = /*$$(*/ "Operation"; /*)*/
|
||||
}
|
||||
@@ -18,85 +18,151 @@
|
||||
package com.axelor.apps.qvm.web;
|
||||
|
||||
import com.axelor.apps.qvm.db.QvmOperation;
|
||||
import com.axelor.apps.qvm.db.repo.QvmOperationRepository;
|
||||
import com.axelor.apps.qvm.service.QvmOperationService;
|
||||
import com.axelor.apps.qvm.service.QvmOperationServiceImpl;
|
||||
import com.axelor.apps.qvm.translation.ITranslation;
|
||||
import com.axelor.auth.AuthUtils;
|
||||
import com.axelor.auth.db.User;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.service.TraceBackService;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.axelor.meta.schema.actions.ActionView;
|
||||
import com.axelor.rpc.ActionRequest;
|
||||
import com.axelor.rpc.ActionResponse;
|
||||
import com.google.inject.Singleton;
|
||||
import com.axelor.rpc.Context;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class QvmOperationController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public void setSequenceOperation(ActionRequest request, ActionResponse response) {
|
||||
public void setSequenceOperation(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createOperationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSequenceCalibration(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createCalibrationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSequenceQualification(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createQualificationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMachineInfo(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
QvmOperation newOperation = Beans.get(QvmOperationService.class).setMachine(calibration);
|
||||
}
|
||||
|
||||
public void generateQvmOperation(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
User user = AuthUtils.getUser();
|
||||
Context context = request.getContext();
|
||||
Long id = (Long) request.getContext().get("id");
|
||||
QvmOperation operation = Beans.get(QvmOperationRepository.class).find(id);
|
||||
if (operation == null) {
|
||||
response.setError("Operation not found.");
|
||||
return;
|
||||
}
|
||||
operation = Beans.get(QvmOperationRepository.class).find(operation.getId());
|
||||
|
||||
// printOperationInformation(operation);
|
||||
QvmOperation nextOperation =
|
||||
Beans.get(QvmOperationService.class).createNextOperation(operation, user.getId());
|
||||
|
||||
// printOperationInformation(nextOperation);
|
||||
if (nextOperation != null) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createOperationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
// Beans.get(QvmOperationRepository.class).save(nextOperation);
|
||||
saveQvmOperation(nextOperation);
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
response.setView(
|
||||
ActionView.define(I18n.get(ITranslation.OPERATION))
|
||||
.model(QvmOperation.class.getName())
|
||||
.add("grid", "operation-grid")
|
||||
.add("form", "operation-form")
|
||||
.param("forceEdit", "true")
|
||||
.context("_showRecord", nextOperation.getId())
|
||||
.map());
|
||||
response.setCanClose(true);
|
||||
} else {
|
||||
response.setError("Failed to create the next operation.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSequenceCalibration(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
public void saveQvmOperation(QvmOperation operation) {
|
||||
EntityManager entityManager = Beans.get(EntityManager.class);
|
||||
EntityTransaction transaction = entityManager.getTransaction();
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createCalibrationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSequenceQualification(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
|
||||
if (calibration != null && calibration.getCompany() != null) {
|
||||
response.setValue(
|
||||
"serialNumber",
|
||||
Beans.get(QvmOperationService.class)
|
||||
.createQualificationSeq(calibration.getCompany())
|
||||
.getSerialNumber());
|
||||
} else {
|
||||
System.out.println("Operation or company est null");
|
||||
System.out.println("Operation : " + calibration);
|
||||
System.out.println("Company : " + calibration.getCompany());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMachineInfo(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
QvmOperation calibration = request.getContext().asType(QvmOperation.class);
|
||||
QvmOperation newOperation = Beans.get(QvmOperationService.class).setMachine(calibration);
|
||||
System.out.println("Is transaction active? " + transaction.isActive());
|
||||
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.persist(operation);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaction != null && transaction.isActive()) {
|
||||
transaction.rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
<entity name="QvmMachineLocation">
|
||||
<string name="name" title="Location" required="true"/>
|
||||
<many-to-one name="parent" ref="com.axelor.apps.qvm.db.QvmMachineLocation" title="parent"/>
|
||||
<!-- <many-to-one name="parent" ref="com.axelor.apps.qvm.db.QvmMachineLocation" title="parent"/> -->
|
||||
<one-to-many name="machineList" ref="com.axelor.apps.production.db.Machine" mappedBy="machineLocation" title="Machine List" />
|
||||
<integer name="orderByState"/>
|
||||
<integer name="stockUnity" selection="operation.parent.location.select" default="0"/>
|
||||
<!-- <integer name="stockUnity" selection="operation.parent.location.select" default="0"/> -->
|
||||
<integer name="qvmParentLocation" selection="operation.parent.location.select" default="0"/>
|
||||
<integer name="typeSelect" title="Type Select" default="0"/>
|
||||
</entity>
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
<many-to-one name="purchaseRequest" ref="com.axelor.apps.purchase.db.PurchaseRequest" />
|
||||
<integer name="parentLocation" selection="operation.parent.location.select" default="0"/>
|
||||
|
||||
<string name="operationOrigin"/>
|
||||
<integer name="creationType" selection="operation.creation.type.select"/>
|
||||
<track>
|
||||
<field name="createdOn"/>
|
||||
<field name="createdBy"/>
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
<string name="fullName" namecolumn="true">
|
||||
<![CDATA[
|
||||
|
||||
return name+" "+stockUnity;
|
||||
if(fullName == null){
|
||||
return name+" "+stockUnity;
|
||||
}else{
|
||||
return fullName;
|
||||
}
|
||||
]]>
|
||||
</string>
|
||||
<string name="name" title="Qvm Operation Type" required="true"/>
|
||||
|
||||
@@ -37,4 +37,9 @@
|
||||
<option value="2">Instrument</option>
|
||||
</selection>
|
||||
|
||||
<selection name="operation.creation.type.select">
|
||||
<option value="1">Created</option>
|
||||
<option value="2">Generated</option>
|
||||
</selection>
|
||||
|
||||
</object-views>
|
||||
Reference in New Issue
Block a user