régler le problème de génération commandes fournisseur
copie les lignes de commande d'achat est leurs TCO quand on click sur le bouton (Générer commandes fournisseurs)
This commit is contained in:
@@ -36,6 +36,8 @@ import com.axelor.apps.purchase.service.app.AppPurchaseService;
|
|||||||
import com.axelor.apps.stock.service.StockLocationService;
|
import com.axelor.apps.stock.service.StockLocationService;
|
||||||
import com.axelor.apps.supplychain.exception.IExceptionMessage;
|
import com.axelor.apps.supplychain.exception.IExceptionMessage;
|
||||||
import com.axelor.apps.supplychain.service.PurchaseOrderServiceSupplychainImpl;
|
import com.axelor.apps.supplychain.service.PurchaseOrderServiceSupplychainImpl;
|
||||||
|
import com.axelor.apps.suppliermanagement.db.repo.PurchaseOrderSupplierLineRepository;
|
||||||
|
import com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine;
|
||||||
import com.axelor.auth.AuthUtils;
|
import com.axelor.auth.AuthUtils;
|
||||||
import com.axelor.exception.AxelorException;
|
import com.axelor.exception.AxelorException;
|
||||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||||
@@ -128,8 +130,9 @@ public class PurchaseOrderSupplierService {
|
|||||||
|
|
||||||
for (Partner supplierPartner : purchaseOrderLinesBySupplierPartner.keySet()) {
|
for (Partner supplierPartner : purchaseOrderLinesBySupplierPartner.keySet()) {
|
||||||
|
|
||||||
this.createPurchaseOrder(
|
PurchaseOrder PurchaseOrderNew = this.createPurchaseOrderSophal(
|
||||||
supplierPartner, purchaseOrderLinesBySupplierPartner.get(supplierPartner), purchaseOrder);
|
supplierPartner, purchaseOrderLinesBySupplierPartner.get(supplierPartner), purchaseOrder);
|
||||||
|
createPurchaseOrderSupplierLineTCO(PurchaseOrderNew.getPurchaseOrderLineList() ,purchaseOrderLinesBySupplierPartner.get(supplierPartner));
|
||||||
}
|
}
|
||||||
|
|
||||||
poRepo.save(purchaseOrder);
|
poRepo.save(purchaseOrder);
|
||||||
@@ -223,4 +226,122 @@ public class PurchaseOrderSupplierService {
|
|||||||
purchaseOrderLine.getQty(),
|
purchaseOrderLine.getQty(),
|
||||||
purchaseOrderLine.getUnit());
|
purchaseOrderLine.getUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional(rollbackOn = {Exception.class})
|
||||||
|
public PurchaseOrder createPurchaseOrderSophal(
|
||||||
|
Partner supplierPartner,
|
||||||
|
List<PurchaseOrderLine> purchaseOrderLineList,
|
||||||
|
PurchaseOrder parentPurchaseOrder)
|
||||||
|
throws AxelorException {
|
||||||
|
|
||||||
|
LOG.debug(
|
||||||
|
"Création d'une commande fournisseur depuis le devis fournisseur : {} et le fournisseur : {}",
|
||||||
|
parentPurchaseOrder.getPurchaseOrderSeq(),
|
||||||
|
supplierPartner.getFullName());
|
||||||
|
|
||||||
|
PurchaseOrder purchaseOrder =
|
||||||
|
purchaseOrderServiceSupplychainImpl.createPurchaseOrder(
|
||||||
|
AuthUtils.getUser(),
|
||||||
|
parentPurchaseOrder.getCompany(),
|
||||||
|
null,
|
||||||
|
supplierPartner.getCurrency(),
|
||||||
|
null,
|
||||||
|
parentPurchaseOrder.getPurchaseOrderSeq(),
|
||||||
|
parentPurchaseOrder.getExternalReference(),
|
||||||
|
Beans.get(StockLocationService.class)
|
||||||
|
.getDefaultReceiptStockLocation(parentPurchaseOrder.getCompany()),
|
||||||
|
Beans.get(AppBaseService.class).getTodayDate(),
|
||||||
|
Beans.get(PartnerPriceListService.class)
|
||||||
|
.getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE),
|
||||||
|
supplierPartner,
|
||||||
|
parentPurchaseOrder.getTradingName());
|
||||||
|
|
||||||
|
purchaseOrder.setParentPurchaseOrder(parentPurchaseOrder);
|
||||||
|
|
||||||
|
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
|
||||||
|
|
||||||
|
// purchaseOrder.addPurchaseOrderLineListItem(
|
||||||
|
// this.createPurchaseOrderLine(purchaseOrder, purchaseOrderLine));
|
||||||
|
purchaseOrder.addPurchaseOrderLineListItem(
|
||||||
|
this.createPurchaseOrderLineSophal(purchaseOrder, purchaseOrderLine));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
purchaseOrderServiceSupplychainImpl.computePurchaseOrder(purchaseOrder);
|
||||||
|
|
||||||
|
purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_REQUESTED);
|
||||||
|
purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
|
||||||
|
|
||||||
|
poRepo.save(purchaseOrder);
|
||||||
|
|
||||||
|
return purchaseOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurchaseOrderLine createPurchaseOrderLineSophal(
|
||||||
|
PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
|
||||||
|
|
||||||
|
|
||||||
|
LOG.debug(
|
||||||
|
"SOPHAL Création d'une ligne de commande fournisseur pour le produit : {}",
|
||||||
|
new Object[] {purchaseOrderLine.getProductName()});
|
||||||
|
|
||||||
|
PurchaseOrderLine PurchaseOrderLineNew = purchaseOrderLineService.createPurchaseOrderLine(
|
||||||
|
purchaseOrder,
|
||||||
|
purchaseOrderLine.getProduct(),
|
||||||
|
purchaseOrderLine.getProductName(),
|
||||||
|
purchaseOrderLine.getDescription(),
|
||||||
|
purchaseOrderLine.getQty(),
|
||||||
|
purchaseOrderLine.getUnit());
|
||||||
|
|
||||||
|
|
||||||
|
PurchaseOrderLineNew.setPrice(purchaseOrderLine.getPrice());
|
||||||
|
PurchaseOrderLineNew.setInTaxPrice(purchaseOrderLine.getInTaxPrice());
|
||||||
|
PurchaseOrderLineNew.setPriceDiscounted(purchaseOrderLine.getPriceDiscounted());
|
||||||
|
PurchaseOrderLineNew.setExTaxTotal(purchaseOrderLine.getExTaxTotal());
|
||||||
|
PurchaseOrderLineNew.setInTaxTotal(purchaseOrderLine.getInTaxTotal());
|
||||||
|
PurchaseOrderLineNew.setDiscountAmount(purchaseOrderLine.getDiscountAmount());
|
||||||
|
PurchaseOrderLineNew.setDiscountTypeSelect(purchaseOrderLine.getDiscountTypeSelect());
|
||||||
|
PurchaseOrderLineNew.setSupplierPartner(purchaseOrderLine.getSupplierPartner());
|
||||||
|
|
||||||
|
return PurchaseOrderLineNew ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void createPurchaseOrderSupplierLineTCO(
|
||||||
|
List<PurchaseOrderLine> purchaseOrderLN, List<PurchaseOrderLine> purchaseOrderLP) throws AxelorException {
|
||||||
|
|
||||||
|
int index=0;
|
||||||
|
List<PurchaseOrderLine> purchaseOrderLineNew = purchaseOrderLN;
|
||||||
|
for (PurchaseOrderLine purchaseOrderLineParnet : purchaseOrderLP) {
|
||||||
|
|
||||||
|
List<PurchaseOrderSupplierLine> PurchaseOrderSupplierLineParnetList =
|
||||||
|
Beans.get(PurchaseOrderSupplierLineRepository.class)
|
||||||
|
.all()
|
||||||
|
.filter("self.purchaseOrderLine =?1 ", purchaseOrderLineParnet.getId())
|
||||||
|
.fetch();
|
||||||
|
|
||||||
|
for (PurchaseOrderSupplierLine poLineSupplierParnet : PurchaseOrderSupplierLineParnetList) {
|
||||||
|
|
||||||
|
PurchaseOrderSupplierLine po = new PurchaseOrderSupplierLine();
|
||||||
|
po.setPrice(poLineSupplierParnet.getPrice());
|
||||||
|
po.setExTaxTotal(poLineSupplierParnet.getExTaxTotal());
|
||||||
|
po.setInTaxTotal(poLineSupplierParnet.getInTaxTotal());
|
||||||
|
po.setTaxTotal(poLineSupplierParnet.getTaxTotal());
|
||||||
|
po.setAvailableQty(poLineSupplierParnet.getAvailableQty());
|
||||||
|
po.setPurchaseOrderLine(purchaseOrderLineNew.get(index));
|
||||||
|
po.setStateSelect(poLineSupplierParnet.getStateSelect());
|
||||||
|
po.setTaxLine(poLineSupplierParnet.getTaxLine());
|
||||||
|
po.setSupplierPartner(poLineSupplierParnet.getSupplierPartner());
|
||||||
|
po.setComments(poLineSupplierParnet.getComments());
|
||||||
|
po.setArchived(poLineSupplierParnet.getArchived());
|
||||||
|
po.setArchived(poLineSupplierParnet.getArchived());
|
||||||
|
po.setEstimatedDelivDate(poLineSupplierParnet.getEstimatedDelivDate());
|
||||||
|
//LOG.debug("purchaseOrderLineNew.getId(): {}",purchaseOrderLineNew.get(index).getId());
|
||||||
|
Beans.get(PurchaseOrderSupplierLineRepository.class).save(po);
|
||||||
|
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user