use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStockMove.
@Override
public StockMove createStockMove(SaleOrder saleOrder, Company company, LocalDate estimatedDeliveryDate) throws AxelorException {
StockLocation toStockLocation = saleOrder.getToStockLocation();
if (toStockLocation == null) {
toStockLocation = partnerStockSettingsService.getDefaultExternalStockLocation(saleOrder.getClientPartner(), company);
}
if (toStockLocation == null) {
toStockLocation = stockConfigService.getCustomerVirtualStockLocation(stockConfigService.getStockConfig(company));
}
Partner partner = computePartnerToUseForStockMove(saleOrder);
StockMove stockMove = stockMoveService.createStockMove(null, saleOrder.getDeliveryAddress(), company, partner, saleOrder.getStockLocation(), toStockLocation, null, estimatedDeliveryDate, saleOrder.getDescription(), saleOrder.getShipmentMode(), saleOrder.getFreightCarrierMode(), saleOrder.getCarrierPartner(), saleOrder.getForwarderPartner(), saleOrder.getIncoterm(), StockMoveRepository.TYPE_OUTGOING);
stockMove.setToAddressStr(saleOrder.getDeliveryAddressStr());
stockMove.setOriginId(saleOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_SALE_ORDER);
stockMove.setOrigin(saleOrder.getSaleOrderSeq());
stockMove.setStockMoveLineList(new ArrayList<>());
stockMove.setTradingName(saleOrder.getTradingName());
stockMove.setSpecificPackage(saleOrder.getSpecificPackage());
stockMove.setNote(saleOrder.getDeliveryComments());
stockMove.setPickingOrderComments(saleOrder.getPickingOrderComments());
stockMove.setGroupProductsOnPrintings(partner.getGroupProductsOnPrintings());
stockMove.setInvoicedPartner(saleOrder.getInvoicedPartner());
if (stockMove.getPartner() != null) {
setDefaultAutoMailSettings(stockMove);
}
return stockMove;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class DeclarationOfExchangesExporterServices method exportToCSV.
// TODO: factorize code to parent.
@Override
protected String exportToCSV() throws AxelorException {
Path path = getFilePath();
Period period = declarationOfExchanges.getPeriod();
List<StockMoveLine> stockMoveLines = Beans.get(StockMoveLineRepository.class).findForDeclarationOfExchanges(period.getFromDate(), period.getToDate(), declarationOfExchanges.getProductTypeSelect(), declarationOfExchanges.getStockMoveTypeSelect(), declarationOfExchanges.getCountry(), declarationOfExchanges.getCompany()).fetch();
List<String[]> dataList = new ArrayList<>(stockMoveLines.size());
int lineNum = 1;
for (StockMoveLine stockMoveLine : stockMoveLines) {
String[] data = new String[columnHeadersList.size()];
StockMove stockMove = stockMoveLine.getStockMove();
BigDecimal fiscalValue = stockMoveLine.getUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
String taxNbr;
if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
if (stockMove.getPartner() == null) {
taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
}
if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
}
taxNbr = stockMove.getPartner().getTaxNbr();
} else {
taxNbr = "";
}
data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum++);
data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
data[columnHeadersList.indexOf(TAKER)] = taxNbr;
dataList.add(data);
}
try {
MoreFiles.createParentDirectories(path);
CsvTool.csvWriter(path.getParent().toString(), path.getFileName().toString(), ';', getTranslatedHeaders(), dataList);
} catch (IOException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getLocalizedMessage());
}
return attach(path.toString());
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method setDefaultInvoicedPartner.
@Override
public void setDefaultInvoicedPartner(StockMove stockMove) {
if (stockMove != null && stockMove.getPartner() != null && stockMove.getPartner().getId() != null) {
Partner partner = Beans.get(PartnerRepository.class).find(stockMove.getPartner().getId());
if (partner != null) {
if (!CollectionUtils.isEmpty(partner.getPartner1SupplychainLinkList())) {
List<PartnerSupplychainLink> partnerSupplychainLinkList = partner.getPartner1SupplychainLinkList();
// Retrieve all Invoiced by Type
List<PartnerSupplychainLink> partnerSupplychainLinkInvoicedByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
// If there is only one, then it is the default one
if (partnerSupplychainLinkInvoicedByList.size() == 1) {
PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
stockMove.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
} else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
stockMove.setInvoicedPartner(partner);
} else {
stockMove.setInvoicedPartner(null);
}
} else {
stockMove.setInvoicedPartner(partner);
}
}
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method isAllocatedStockMoveLineRemoved.
@Override
public boolean isAllocatedStockMoveLineRemoved(StockMove stockMove) {
StockMove storedStockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
Boolean isAllocatedStockMoveLineRemoved = false;
if (ObjectUtils.notEmpty(storedStockMove)) {
List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
List<StockMoveLine> storedStockMoveLineList = storedStockMove.getStockMoveLineList();
if (stockMoveLineList != null && storedStockMoveLineList != null) {
for (StockMoveLine stockMoveLine : storedStockMoveLineList) {
if (Beans.get(StockMoveLineServiceSupplychain.class).isAllocatedStockMoveLine(stockMoveLine) && !stockMoveLineList.contains(stockMoveLine)) {
stockMoveLineList.add(stockMoveLine);
isAllocatedStockMoveLineRemoved = true;
}
if (isAllocatedStockMoveLineRemoved) {
stockMove.setStockMoveLineList(stockMoveLineList);
}
}
}
}
return isAllocatedStockMoveLineRemoved;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.
@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
return null;
}
if (stockMoveLineList.size() == 1) {
return stockMoveLineList.get(0);
}
StockMove stockMove = stockMoveLineList.get(0).getStockMove();
SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
Product product;
String productName;
String description;
BigDecimal quantity = BigDecimal.ZERO;
Unit unit;
if (saleOrderLine != null) {
product = saleOrderLine.getProduct();
productName = saleOrderLine.getProductName();
description = saleOrderLine.getDescription();
unit = saleOrderLine.getUnit();
} else if (purchaseOrderLine != null) {
product = purchaseOrderLine.getProduct();
productName = purchaseOrderLine.getProductName();
description = purchaseOrderLine.getDescription();
unit = purchaseOrderLine.getUnit();
} else {
// shouldn't ever happen or you misused this function
return null;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
quantity = quantity.add(stockMoveLine.getRealQty());
}
StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
generatedStockMoveLine.setIsMergedStockMoveLine(true);
return generatedStockMoveLine;
}
Aggregations