use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineController method fillMaxDiscount.
/**
* Called from sale order line form view on load and on discount type select change. Call {@link
* SaleOrderLineService#computeMaxDiscount} and set the message to the view.
*
* @param request
* @param response
*/
public void fillMaxDiscount(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
BigDecimal maxDiscount = saleOrderLineService.computeMaxDiscount(saleOrder, saleOrderLine);
response.setValue("$maxDiscount", maxDiscount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineController method computeSubMargin.
public void computeSubMargin(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
saleOrderLine.setSaleOrder(saleOrder);
Map<String, BigDecimal> map = saleOrderLineService.computeSubMargin(saleOrder, saleOrderLine);
response.setValues(map);
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class ImportSaleOrder method importSaleOrder.
public Object importSaleOrder(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof SaleOrder;
SaleOrder saleOrder = (SaleOrder) bean;
saleOrderService.computeAddressStr(saleOrder);
saleOrder = saleOrderComputeService.computeSaleOrder(saleOrder);
if (saleOrder.getStatusSelect() == 1) {
saleOrder.setSaleOrderSeq(sequenceService.getDraftSequenceNumber(saleOrder));
saleOrderRepo.computeFullName(saleOrder);
} else {
saleOrderWorkflowService.finalizeQuotation(saleOrder);
}
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class MapRestSale method getGeoMapData.
@Path("/geomap/turnover")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {
Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
JsonNodeFactory factory = JsonNodeFactory.instance;
ObjectNode mainNode = factory.objectNode();
ArrayNode arrayNode = factory.arrayNode();
ArrayNode labelNode = factory.arrayNode();
labelNode.add("Country");
labelNode.add("Turnover");
arrayNode.add(labelNode);
for (SaleOrder so : orders) {
Country country = so.getMainInvoicingAddress().getAddressL7Country();
BigDecimal value = so.getExTaxTotal();
if (country != null) {
String key = country.getName();
if (data.containsKey(key)) {
BigDecimal oldValue = data.get(key);
oldValue = oldValue.add(value);
data.put(key, oldValue);
} else {
data.put(key, value);
}
}
}
Iterator<String> keys = data.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
ArrayNode dataNode = factory.arrayNode();
dataNode.add(key);
dataNode.add(data.get(key));
arrayNode.add(dataNode);
}
mainNode.put("status", 0);
mainNode.set("data", arrayNode);
return mainNode;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class OpportunitySaleOrderController method generateSaleOrder.
public void generateSaleOrder(ActionRequest request, ActionResponse response) throws AxelorException {
Opportunity opportunity = request.getContext().asType(Opportunity.class);
opportunity = Beans.get(OpportunityRepository.class).find(opportunity.getId());
SaleOrder saleOrder = Beans.get(OpportunitySaleOrderService.class).createSaleOrderFromOpportunity(opportunity);
response.setReload(true);
response.setView(ActionView.define(I18n.get(ITranslation.SALE_QUOTATION)).model(SaleOrder.class.getName()).add("form", "sale-order-form").param("forceEdit", "true").param("forceTitle", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
}
Aggregations