use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderCreateServiceImpl method createSaleOrder.
@Override
public SaleOrder createSaleOrder(User salespersonUser, Company company, Partner contactPartner, Currency currency, LocalDate deliveryDate, String internalReference, String externalReference, PriceList priceList, Partner clientPartner, Team team, TradingName tradingName) throws AxelorException {
logger.debug("Création d'un devis client : Société = {}, Reference externe = {}, Client = {}", company, externalReference, clientPartner.getFullName());
SaleOrder saleOrder = new SaleOrder();
saleOrder.setClientPartner(clientPartner);
saleOrder.setCreationDate(appSaleService.getTodayDate(company));
saleOrder.setContactPartner(contactPartner);
saleOrder.setCurrency(currency);
saleOrder.setExternalReference(externalReference);
saleOrder.setDeliveryDate(deliveryDate);
saleOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(tradingName, company));
if (salespersonUser == null) {
salespersonUser = AuthUtils.getUser();
}
saleOrder.setSalespersonUser(salespersonUser);
if (team == null) {
team = salespersonUser.getActiveTeam();
}
saleOrder.setTeam(team);
if (company == null) {
company = salespersonUser.getActiveCompany();
}
saleOrder.setCompany(company);
saleOrder.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
saleOrder.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
saleOrderService.computeAddressStr(saleOrder);
if (priceList == null) {
priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE);
}
saleOrder.setPriceList(priceList);
saleOrder.setSaleOrderLineList(new ArrayList<>());
saleOrder.setStatusSelect(SaleOrderRepository.STATUS_DRAFT_QUOTATION);
saleOrderService.computeEndOfValidityDate(saleOrder);
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderCreateServiceImpl method mergeSaleOrders.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder mergeSaleOrders(List<SaleOrder> saleOrderList, Currency currency, Partner clientPartner, Company company, Partner contactPartner, PriceList priceList, Team team) throws AxelorException {
String numSeq = "";
String externalRef = "";
for (SaleOrder saleOrderLocal : saleOrderList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
numSeq += saleOrderLocal.getSaleOrderSeq();
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (saleOrderLocal.getExternalReference() != null) {
externalRef += saleOrderLocal.getExternalReference();
}
}
SaleOrder saleOrderMerged = this.createSaleOrder(AuthUtils.getUser(), company, contactPartner, currency, null, numSeq, externalRef, priceList, clientPartner, team);
this.attachToNewSaleOrder(saleOrderList, saleOrderMerged);
saleOrderComputeService.computeSaleOrder(saleOrderMerged);
saleOrderRepo.save(saleOrderMerged);
this.removeOldSaleOrders(saleOrderList);
return saleOrderMerged;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderCreateServiceImpl method attachToNewSaleOrder.
// Attachment of all sale order lines to new sale order
protected void attachToNewSaleOrder(List<SaleOrder> saleOrderList, SaleOrder saleOrderMerged) {
for (SaleOrder saleOrder : saleOrderList) {
int countLine = 1;
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
saleOrderLine.setSequence(countLine * 10);
saleOrderMerged.addSaleOrderLineListItem(saleOrderLine);
countLine++;
}
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method manageComplementaryProductSaleOrderLine.
@Override
public List<SaleOrderLine> manageComplementaryProductSaleOrderLine(SaleOrderLine saleOrderLine, SaleOrder saleOrder, List<ComplementaryProduct> complementaryProducts) throws AxelorException {
List<SaleOrderLine> newComplementarySOLines = new ArrayList<>();
if (saleOrderLine.getComplementarySaleOrderLineList() == null) {
saleOrderLine.setComplementarySaleOrderLineList(new ArrayList<>());
}
for (ComplementaryProduct complementaryProduct : complementaryProducts) {
Product product = complementaryProduct.getProduct();
if (product == null) {
continue;
}
SaleOrderLine complementarySOLine;
Optional<SaleOrderLine> complementarySOLineOpt = saleOrderLine.getComplementarySaleOrderLineList().stream().filter(line -> line.getMainSaleOrderLine() != null && line.getProduct().equals(product)).findFirst();
if (complementarySOLineOpt.isPresent()) {
complementarySOLine = complementarySOLineOpt.get();
} else {
complementarySOLine = new SaleOrderLine();
complementarySOLine.setSequence(saleOrderLine.getSequence());
complementarySOLine.setProduct(complementaryProduct.getProduct());
saleOrderLine.addComplementarySaleOrderLineListItem(complementarySOLine);
newComplementarySOLines.add(complementarySOLine);
}
complementarySOLine.setQty(complementaryProduct.getQty());
this.computeProductInformation(complementarySOLine, saleOrder);
this.computeValues(saleOrder, complementarySOLine);
saleOrderLineRepo.save(complementarySOLine);
}
return newComplementarySOLines;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method getSaleOrder.
@Override
public SaleOrder getSaleOrder(Context context) {
Context parentContext = context.getParent();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (parentContext != null && !parentContext.getContextClass().equals(SaleOrder.class)) {
parentContext = parentContext.getParent();
}
if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
saleOrder = parentContext.asType(SaleOrder.class);
}
return saleOrder;
}
Aggregations