vérifier si tous TCO sont validées

This commit is contained in:
walid seghier
2022-07-19 10:31:32 +01:00
parent 4216b099dc
commit a1fcae2a9c
2 changed files with 57 additions and 1 deletions

View File

@@ -63,4 +63,6 @@ public interface IExceptionMessage {
"There is no sequence set for the purchase requests for the company %s" /*)*/;
public static final String PURCHASE_REQUEST_MISSING_SUPPLIER_USER = /*$$(*/
"Please enter supplier for following purchase request : %s" /*)*/;
public static final String TCO = /*$$(*/
"CTO not validated for products : %s" /*)*/;
}

View File

@@ -44,6 +44,7 @@ import com.axelor.apps.purchase.db.PurchaseOrderLine;
import com.axelor.apps.purchase.db.PurchaseOrderLineTax;
import com.axelor.apps.purchase.db.repo.ImportationFolderRepository;
import com.axelor.apps.purchase.db.repo.PurchaseOrderRepository;
import com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository;
import com.axelor.apps.purchase.exception.IExceptionMessage;
import com.axelor.apps.purchase.report.IReport;
import com.axelor.apps.purchase.service.app.AppPurchaseService;
@@ -59,13 +60,15 @@ import com.google.inject.Inject;
import com.google.inject.persist.Transactional;
import com.axelor.apps.base.db.CancelReason;
import wslite.json.JSONException;
import java.lang.invoke.MethodHandles;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -459,6 +462,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
@Override
@Transactional(rollbackOn = {Exception.class})
public void validatePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException, MalformedURLException, JSONException {
checkAllTco(purchaseOrder);
computePurchaseOrder(purchaseOrder);
purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_VALIDATED);
@@ -544,4 +548,54 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
}
purchaseOrderRepo.save(purchaseOrder);
}
public void checkAllTco(PurchaseOrder purchaseOrder) throws AxelorException{
/*vérifier si tous les tco sont validées */
PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
javax.persistence.Query dateQuery =
com.axelor
.db
.JPA
.em()
.createNativeQuery(
"SELECT a.id FROM purchase_purchase_order_line as a "+
"left join public.suppliermanagement_purchase_order_supplier_line as b on a.id = b.purchase_order_line "+
"where a.purchase_order = "+purchaseOrder.getId()+" and b.state_select = 3 and ( a.archived is not true or b.archived is not true ) "+
"group by a.id , b.state_select ");
List<BigInteger> purchaseOrdeLineAccepted = dateQuery.getResultList();
javax.persistence.Query dateQueryTow =
com.axelor
.db
.JPA
.em()
.createNativeQuery(
"SELECT a.id FROM purchase_purchase_order_line as a "+
"left join public.suppliermanagement_purchase_order_supplier_line as b on a.id = b.purchase_order_line "+
"where a.purchase_order = "+purchaseOrder.getId()+" and ( a.archived is not true or b.archived is not true ) "+
"group by a.id");
List<BigInteger> purchaseOrdeLineAll = dateQueryTow.getResultList();
// subtracting Lists
Set<BigInteger> purchaseOrdeLineIdsDiff = purchaseOrdeLineAll.stream()
.filter(item -> !purchaseOrdeLineAccepted.contains(item))
.collect(Collectors.toSet());
List<String> Products = new ArrayList<>();
for (BigInteger id : purchaseOrdeLineIdsDiff) {
PurchaseOrderLine purchaseOrderLine = Beans.get(PurchaseOrderLineRepository.class).find(id.longValue());
Products.add(purchaseOrderLine.getProductName());
}
if(purchaseOrdeLineAccepted.size() != purchaseOrdeLineAll.size()){
throw new AxelorException(
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
I18n.get(IExceptionMessage.TCO),
Products);
}
}
}