Purchase Request : check product family
Check purchase request line product family if it same with purchase requests
This commit is contained in:
@@ -20,7 +20,9 @@ package com.axelor.apps.purchase.web;
|
|||||||
import com.axelor.apps.message.service.MailAccountService;
|
import com.axelor.apps.message.service.MailAccountService;
|
||||||
import com.axelor.apps.purchase.db.PurchaseOrder;
|
import com.axelor.apps.purchase.db.PurchaseOrder;
|
||||||
import com.axelor.apps.purchase.db.PurchaseRequest;
|
import com.axelor.apps.purchase.db.PurchaseRequest;
|
||||||
|
import com.axelor.apps.purchase.db.PurchaseRequestLine;
|
||||||
import com.axelor.apps.purchase.db.repo.PurchaseRequestRepository;
|
import com.axelor.apps.purchase.db.repo.PurchaseRequestRepository;
|
||||||
|
import com.axelor.apps.purchase.db.repo.PurchaseRequestLineRepository;
|
||||||
import com.axelor.apps.purchase.exception.IExceptionMessage;
|
import com.axelor.apps.purchase.exception.IExceptionMessage;
|
||||||
import com.axelor.apps.purchase.service.PurchaseRequestService;
|
import com.axelor.apps.purchase.service.PurchaseRequestService;
|
||||||
import com.axelor.apps.tool.StringTool;
|
import com.axelor.apps.tool.StringTool;
|
||||||
@@ -241,5 +243,39 @@ public class PurchaseRequestController {
|
|||||||
public void sendEmail(String email,String subject,String body){
|
public void sendEmail(String email,String subject,String body){
|
||||||
EmailUtil.sendEmail(mailAccountService, email,subject, body);
|
EmailUtil.sendEmail(mailAccountService, email,subject, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkProductFamily(ActionRequest request, ActionResponse response) throws AxelorException {
|
||||||
|
|
||||||
|
Long id = request.getContext().asType(PurchaseRequest.class).getId();
|
||||||
|
PurchaseRequest purchaseRequest = Beans.get(PurchaseRequestRepository.class).find(id);
|
||||||
|
String productFamily = purchaseRequest.getFamilleProduit().getName().toString();
|
||||||
|
Integer size = 0;
|
||||||
|
|
||||||
|
List<PurchaseRequestLine> purchaseRequestLines =
|
||||||
|
Beans.get(PurchaseRequestLineRepository.class)
|
||||||
|
.all()
|
||||||
|
.filter("self.newProduct = ?1 and self.purchaseRequest = ?2",false,id)
|
||||||
|
.fetch();
|
||||||
|
|
||||||
|
if (purchaseRequestLines != null){
|
||||||
|
|
||||||
|
size = purchaseRequestLines.stream()
|
||||||
|
.collect(Collectors.groupingBy(fa -> fa.getProduct().getFamilleProduit())).size();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (size > 1){
|
||||||
|
response.setError(I18n.get("Lines of expression of needs are not of the same family :") +productFamily);
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
if (size == 1){
|
||||||
|
long idOfFamily = purchaseRequestLines.stream()
|
||||||
|
.collect(Collectors.groupingBy(fa -> fa.getProduct().getFamilleProduit().getId()))
|
||||||
|
.keySet().stream().collect(Collectors.toList()).get(0);
|
||||||
|
|
||||||
|
if (purchaseRequest.getFamilleProduit().getId() != idOfFamily){
|
||||||
|
response.setError(I18n.get("Lines of expression of needs are not of the same family :") +productFamily);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user