use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method getPurchaseOrder.
public PurchaseOrder getPurchaseOrder(Context context) {
Context parentContext = context.getParent();
PurchaseOrder purchaseOrder = null;
if (parentContext != null && parentContext.getContextClass() == PurchaseOrder.class) {
purchaseOrder = parentContext.asType(PurchaseOrder.class);
if (!parentContext.getContextClass().toString().equals(PurchaseOrder.class.toString())) {
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
purchaseOrder = purchaseOrderLine.getPurchaseOrder();
}
} else {
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
purchaseOrder = purchaseOrderLine.getPurchaseOrder();
}
return purchaseOrder;
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method getTaxEquiv.
public void getTaxEquiv(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
PurchaseOrder purchaseOrder = getPurchaseOrder(context);
response.setValue("taxEquiv", null);
if (purchaseOrder == null || purchaseOrderLine == null || purchaseOrder.getSupplierPartner() == null || purchaseOrderLine.getTaxLine() == null)
return;
response.setValue("taxEquiv", Beans.get(FiscalPositionService.class).getTaxEquiv(purchaseOrder.getSupplierPartner().getFiscalPosition(), purchaseOrderLine.getTaxLine().getTax()));
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method mergePurchaseOrders.
@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder mergePurchaseOrders(List<PurchaseOrder> purchaseOrderList, Currency currency, Partner supplierPartner, Company company, Partner contactPartner, PriceList priceList, TradingName tradingName) throws AxelorException {
String numSeq = "";
String externalRef = "";
for (PurchaseOrder purchaseOrderLocal : purchaseOrderList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
numSeq += purchaseOrderLocal.getPurchaseOrderSeq();
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (purchaseOrderLocal.getExternalReference() != null) {
externalRef += purchaseOrderLocal.getExternalReference();
}
}
PurchaseOrder purchaseOrderMerged = this.createPurchaseOrder(AuthUtils.getUser(), company, contactPartner, currency, null, numSeq, externalRef, appPurchaseService.getTodayDate(company), priceList, supplierPartner, tradingName);
this.attachToNewPurchaseOrder(purchaseOrderList, purchaseOrderMerged);
this.computePurchaseOrder(purchaseOrderMerged);
purchaseOrderRepo.save(purchaseOrderMerged);
this.removeOldPurchaseOrders(purchaseOrderList);
return purchaseOrderMerged;
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method attachToNewPurchaseOrder.
// Attachment of all purchase order lines to new purchase order
public void attachToNewPurchaseOrder(List<PurchaseOrder> purchaseOrderList, PurchaseOrder purchaseOrderMerged) {
for (PurchaseOrder purchaseOrder : purchaseOrderList) {
int countLine = 1;
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
purchaseOrderLine.setSequence(countLine * 10);
purchaseOrderMerged.addPurchaseOrderLineListItem(purchaseOrderLine);
countLine++;
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseRequestServiceImpl method generatePo.
@Transactional(rollbackOn = { Exception.class })
@Override
public List<PurchaseOrder> generatePo(List<PurchaseRequest> purchaseRequests, Boolean groupBySupplier, Boolean groupByProduct) throws AxelorException {
List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>();
Map<String, PurchaseOrder> purchaseOrderMap = new HashMap<>();
for (PurchaseRequest purchaseRequest : purchaseRequests) {
PurchaseOrder purchaseOrder;
String key = groupBySupplier ? getPurchaseOrderGroupBySupplierKey(purchaseRequest) : null;
if (key != null && purchaseOrderMap.containsKey(key)) {
purchaseOrder = purchaseOrderMap.get(key);
} else {
purchaseOrder = createPurchaseOrder(purchaseRequest);
key = key == null ? purchaseRequest.getId().toString() : key;
purchaseOrderMap.put(key, purchaseOrder);
}
if (purchaseOrder == null) {
purchaseOrder = createPurchaseOrder(purchaseRequest);
}
for (PurchaseRequestLine purchaseRequestLine : purchaseRequest.getPurchaseRequestLineList()) {
PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
Product product = purchaseRequestLine.getProduct();
purchaseOrderLine = groupByProduct && purchaseOrder != null ? getPoLineByProduct(product, purchaseOrder) : null;
purchaseOrderLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, purchaseRequestLine.getNewProduct() ? purchaseRequestLine.getProductTitle() : null, null, purchaseRequestLine.getQuantity(), purchaseRequestLine.getUnit());
purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
purchaseOrderLineList.add(purchaseOrderLine);
purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrder);
}
purchaseOrder.getPurchaseOrderLineList().addAll(purchaseOrderLineList);
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrderRepo.save(purchaseOrder);
purchaseRequest.setPurchaseOrder(purchaseOrder);
purchaseRequestRepo.save(purchaseRequest);
}
List<PurchaseOrder> purchaseOrders = purchaseOrderMap.values().stream().collect(Collectors.toList());
return purchaseOrders;
}
Aggregations