use of com.axelor.apps.base.db.AppSupplychain in project axelor-open-suite by axelor.
the class ProjectBusinessServiceImpl method generateQuotation.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateQuotation(Project project) throws AxelorException {
SaleOrder order = Beans.get(SaleOrderCreateService.class).createSaleOrder(project.getCompany());
Partner clientPartner = project.getClientPartner();
Partner contactPartner = project.getContactPartner();
if (contactPartner == null && clientPartner.getContactPartnerSet().size() == 1) {
contactPartner = clientPartner.getContactPartnerSet().iterator().next();
}
Company company = project.getCompany();
order.setProject(projectRepo.find(project.getId()));
order.setClientPartner(clientPartner);
order.setContactPartner(contactPartner);
order.setCompany(company);
order.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
order.setMainInvoicingAddressStr(addressService.computeAddressStr(order.getMainInvoicingAddress()));
order.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
order.setDeliveryAddressStr(addressService.computeAddressStr(order.getDeliveryAddress()));
order.setIsNeedingConformityCertificate(clientPartner.getIsNeedingConformityCertificate());
order.setCompanyBankDetails(Beans.get(AccountingSituationService.class).getCompanySalesBankDetails(company, clientPartner));
if (project.getCurrency() != null) {
order.setCurrency(project.getCurrency());
} else if (clientPartner.getCurrency() != null) {
order.setCurrency(clientPartner.getCurrency());
} else {
order.setCurrency(company.getCurrency());
}
if (project.getPriceList() != null) {
order.setPriceList(project.getPriceList());
} else {
order.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE));
}
if (order.getPriceList() != null) {
order.setHideDiscount(order.getPriceList().getHideDiscount());
}
if (clientPartner.getPaymentCondition() != null) {
order.setPaymentCondition(clientPartner.getPaymentCondition());
} else {
if (company != null && company.getAccountConfig() != null) {
order.setPaymentCondition(company.getAccountConfig().getDefPaymentCondition());
}
}
if (clientPartner.getInPaymentMode() != null) {
order.setPaymentMode(clientPartner.getInPaymentMode());
} else {
if (company != null && company.getAccountConfig() != null) {
order.setPaymentMode(company.getAccountConfig().getInPaymentMode());
}
}
AppSupplychain appSupplychain = Beans.get(AppSupplychainService.class).getAppSupplychain();
if (appSupplychain != null) {
order.setShipmentMode(clientPartner.getShipmentMode());
order.setFreightCarrierMode(clientPartner.getFreightCarrierMode());
if (clientPartner.getFreightCarrierMode() != null) {
order.setCarrierPartner(clientPartner.getFreightCarrierMode().getCarrierPartner());
}
Boolean interco = appSupplychain.getIntercoFromSale() && !order.getCreatedByInterco() && clientPartner != null && Beans.get(CompanyRepository.class).all().filter("self.partner = ?", clientPartner).fetchOne() != null;
order.setInterco(interco);
// Automatic invoiced and delivered partners set in case of partner delegations
if (appSupplychain.getActivatePartnerRelations()) {
Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(order);
}
}
return Beans.get(SaleOrderRepository.class).save(order);
}
use of com.axelor.apps.base.db.AppSupplychain in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method verifyProductStock.
@Override
public void verifyProductStock(StockMove stockMove) throws AxelorException {
AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
if (stockMove.getAvailabilityRequest() && stockMove.getStockMoveLineList() != null && appSupplychain.getIsVerifyProductStock() && stockMove.getFromStockLocation() != null) {
StringJoiner notAvailableProducts = new StringJoiner(",");
int counter = 1;
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
boolean isAvailableProduct = stockMoveLineServiceSupplychain.isAvailableProduct(stockMove, stockMoveLine);
if (!isAvailableProduct && counter <= 10) {
notAvailableProducts.add(stockMoveLine.getProduct().getFullName());
counter++;
}
}
if (!Strings.isNullOrEmpty(notAvailableProducts.toString())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.STOCK_MOVE_VERIFY_PRODUCT_STOCK_ERROR), notAvailableProducts.toString()));
}
}
}
use of com.axelor.apps.base.db.AppSupplychain in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method realize.
@Override
@Transactional(rollbackOn = { Exception.class })
public String realize(StockMove stockMove, boolean check) throws AxelorException {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return super.realize(stockMove, check);
}
LOG.debug("RĂ©alisation du mouvement de stock : {} ", stockMove.getStockMoveSeq());
String newStockSeq = super.realize(stockMove, check);
AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updateSaleOrderLinesDeliveryState(stockMove, !stockMove.getIsReversion());
// Update linked saleOrder delivery state depending on BackOrder's existence
SaleOrder saleOrder = saleOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
saleOrder.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
} else {
Beans.get(SaleOrderStockService.class).updateDeliveryState(saleOrder);
if (appSupplychain.getTerminateSaleOrderOnDelivery()) {
terminateOrConfirmSaleOrderStatus(saleOrder);
}
}
Beans.get(SaleOrderRepository.class).save(saleOrder);
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updatePurchaseOrderLines(stockMove, !stockMove.getIsReversion());
// Update linked purchaseOrder receipt state depending on BackOrder's existence
PurchaseOrder purchaseOrder = purchaseOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
} else {
Beans.get(PurchaseOrderStockService.class).updateReceiptState(purchaseOrder);
if (appSupplychain.getTerminatePurchaseOrderOnReceipt()) {
finishOrValidatePurchaseOrderStatus(purchaseOrder);
}
}
Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
}
if (appSupplyChainService.getAppSupplychain().getManageStockReservation()) {
Beans.get(ReservedQtyService.class).updateReservedQuantity(stockMove, StockMoveRepository.STATUS_REALIZED);
}
detachNonDeliveredStockMoveLines(stockMove);
List<Long> trackingNumberIds = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getTrackingNumber).filter(Objects::nonNull).map(TrackingNumber::getId).filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(trackingNumberIds)) {
Query update = JPA.em().createQuery("UPDATE FixedAsset self SET self.stockLocation = :stockLocation WHERE self.trackingNumber.id IN (:trackingNumber)");
update.setParameter("stockLocation", stockMove.getToStockLocation());
update.setParameter("trackingNumber", trackingNumberIds);
update.executeUpdate();
}
return newStockSeq;
}
Aggregations