use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderController method updateProductQtyWithPackHeaderQty.
public void updateProductQtyWithPackHeaderQty(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
if (Boolean.FALSE.equals(Beans.get(AppSaleService.class).getAppSale().getEnablePackManagement()) || !Beans.get(SaleOrderLineService.class).isStartOfPackTypeLineQtyChanged(saleOrder.getSaleOrderLineList())) {
return;
}
try {
Beans.get(SaleOrderService.class).updateProductQtyWithPackHeaderQty(saleOrder);
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
response.setReload(true);
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderController method mergeSaleOrder.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeSaleOrder(ActionRequest request, ActionResponse response) {
List<SaleOrder> saleOrderList = new ArrayList<SaleOrder>();
List<Long> saleOrderIdList = new ArrayList<Long>();
boolean fromPopup = false;
String lineToMerge;
if (request.getContext().get("saleQuotationToMerge") != null) {
lineToMerge = "saleQuotationToMerge";
} else {
lineToMerge = "saleOrderToMerge";
}
if (request.getContext().get(lineToMerge) != null) {
if (request.getContext().get(lineToMerge) instanceof List) {
// No confirmation popup, sale orders are content in a parameter list
List<Map> saleOrderMap = (List<Map>) request.getContext().get(lineToMerge);
for (Map map : saleOrderMap) {
saleOrderIdList.add(new Long((Integer) map.get("id")));
}
} else {
// After confirmation popup, sale order's id are in a string separated by ","
String saleOrderIdListStr = (String) request.getContext().get(lineToMerge);
for (String saleOrderId : saleOrderIdListStr.split(",")) {
saleOrderIdList.add(new Long(saleOrderId));
}
fromPopup = true;
}
}
// Check if currency, clientPartner and company are the same for all selected sale orders
Currency commonCurrency = null;
Partner commonClientPartner = null;
Company commonCompany = null;
Partner commonContactPartner = null;
Team commonTeam = null;
// Useful to determine if a difference exists between teams of all sale orders
boolean existTeamDiff = false;
// Useful to determine if a difference exists between contact partners of all sale orders
boolean existContactPartnerDiff = false;
PriceList commonPriceList = null;
// Useful to determine if a difference exists between price lists of all sale orders
boolean existPriceListDiff = false;
SaleOrder saleOrderTemp;
int count = 1;
for (Long saleOrderId : saleOrderIdList) {
saleOrderTemp = JPA.em().find(SaleOrder.class, saleOrderId);
saleOrderList.add(saleOrderTemp);
if (count == 1) {
commonCurrency = saleOrderTemp.getCurrency();
commonClientPartner = saleOrderTemp.getClientPartner();
commonCompany = saleOrderTemp.getCompany();
commonContactPartner = saleOrderTemp.getContactPartner();
commonTeam = saleOrderTemp.getTeam();
commonPriceList = saleOrderTemp.getPriceList();
} else {
if (commonCurrency != null && !commonCurrency.equals(saleOrderTemp.getCurrency())) {
commonCurrency = null;
}
if (commonClientPartner != null && !commonClientPartner.equals(saleOrderTemp.getClientPartner())) {
commonClientPartner = null;
}
if (commonCompany != null && !commonCompany.equals(saleOrderTemp.getCompany())) {
commonCompany = null;
}
if (commonContactPartner != null && !commonContactPartner.equals(saleOrderTemp.getContactPartner())) {
commonContactPartner = null;
existContactPartnerDiff = true;
}
if (commonTeam != null && !commonTeam.equals(saleOrderTemp.getTeam())) {
commonTeam = null;
existTeamDiff = true;
}
if (commonPriceList != null && !commonPriceList.equals(saleOrderTemp.getPriceList())) {
commonPriceList = null;
existPriceListDiff = true;
}
}
count++;
}
StringBuilder fieldErrors = new StringBuilder();
if (commonCurrency == null) {
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_CURRENCY));
}
if (commonClientPartner == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_CLIENT_PARTNER));
}
if (commonCompany == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_COMPANY));
}
if (fieldErrors.length() > 0) {
response.setFlash(fieldErrors.toString());
return;
}
// Check if priceList or contactPartner are content in parameters
if (request.getContext().get("priceList") != null) {
commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
if (request.getContext().get("team") != null) {
commonTeam = JPA.em().find(Team.class, new Long((Integer) ((Map) request.getContext().get("team")).get("id")));
}
if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existTeamDiff)) {
// Need to display intermediate screen to select some values
ActionViewBuilder confirmView = ActionView.define("Confirm merge sale order").model(Wizard.class.getName()).add("form", "sale-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (existPriceListDiff) {
confirmView.context("contextPriceListToCheck", "true");
}
if (existContactPartnerDiff) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", commonClientPartner.getId().toString());
}
if (existTeamDiff) {
confirmView.context("contextTeamToCheck", "true");
}
confirmView.context(lineToMerge, Joiner.on(",").join(saleOrderIdList));
response.setView(confirmView.map());
return;
}
try {
SaleOrder saleOrder = Beans.get(SaleOrderCreateService.class).mergeSaleOrders(saleOrderList, commonCurrency, commonClientPartner, commonCompany, commonContactPartner, commonPriceList, commonTeam);
if (saleOrder != null) {
// Open the generated sale order in a new tab
response.setView(ActionView.define("Sale order").model(SaleOrder.class.getName()).add("grid", "sale-order-grid").add("form", "sale-order-form").param("search-filters", "sale-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
response.setCanClose(true);
}
} catch (Exception e) {
response.setFlash(e.getLocalizedMessage());
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class ConfiguratorController method generateForSaleOrder.
/**
* Called from configurator wizard form view, call {@link
* ConfiguratorService#addLineToSaleOrder(Configurator, SaleOrder, JsonContext, JsonContext)}
*
* @param request
* @param response
*/
public void generateForSaleOrder(ActionRequest request, ActionResponse response) {
Configurator configurator = request.getContext().asType(Configurator.class);
long saleOrderId = ((Integer) request.getContext().get("_saleOrderId")).longValue();
JsonContext jsonAttributes = (JsonContext) request.getContext().get("$attributes");
JsonContext jsonIndicators = (JsonContext) request.getContext().get("$indicators");
configurator = Beans.get(ConfiguratorRepository.class).find(configurator.getId());
SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrderId);
try {
Beans.get(ConfiguratorService.class).addLineToSaleOrder(configurator, saleOrder, jsonAttributes, jsonIndicators);
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class OpportunitySaleOrderServiceImpl method createSaleOrderFromOpportunity.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder createSaleOrderFromOpportunity(Opportunity opportunity) throws AxelorException {
Currency currency = null;
Company company = opportunity.getCompany();
if (opportunity.getCurrency() != null) {
currency = opportunity.getCurrency();
} else if (opportunity.getPartner() != null && opportunity.getPartner().getCurrency() != null) {
currency = opportunity.getPartner().getCurrency();
} else if (company != null) {
currency = company.getCurrency();
}
SaleOrder saleOrder = createSaleOrder(opportunity, currency);
opportunity.addSaleOrderListItem(saleOrder);
if (opportunity.getSalesStageSelect() < OpportunityRepository.SALES_STAGE_PROPOSITION) {
opportunity.setSalesStageSelect(OpportunityRepository.SALES_STAGE_PROPOSITION);
}
saleOrder.setTradingName(opportunity.getTradingName());
saleOrderRepo.save(saleOrder);
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderCreateServiceImpl method createSaleOrder.
@Override
public SaleOrder createSaleOrder(Company company) throws AxelorException {
SaleOrder saleOrder = new SaleOrder();
saleOrder.setCreationDate(appSaleService.getTodayDate(company));
if (company != null) {
saleOrder.setCompany(company);
saleOrder.setCurrency(company.getCurrency());
}
saleOrder.setSalespersonUser(AuthUtils.getUser());
saleOrder.setTeam(saleOrder.getSalespersonUser().getActiveTeam());
saleOrder.setStatusSelect(SaleOrderRepository.STATUS_DRAFT_QUOTATION);
saleOrderService.computeEndOfValidityDate(saleOrder);
return saleOrder;
}
Aggregations