Search in sources :

Example 81 with SaleOrder

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);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 82 with SaleOrder

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);
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 83 with SaleOrder

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;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 84 with 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) Country(com.axelor.apps.base.db.Country) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 85 with SaleOrder

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());
}
Also used : Opportunity(com.axelor.apps.crm.db.Opportunity) OpportunitySaleOrderService(com.axelor.apps.sale.service.saleorder.OpportunitySaleOrderService) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)129 AxelorException (com.axelor.exception.AxelorException)53 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)35 BigDecimal (java.math.BigDecimal)24 Context (com.axelor.rpc.Context)20 Transactional (com.google.inject.persist.Transactional)19 ArrayList (java.util.ArrayList)19 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)18 Company (com.axelor.apps.base.db.Company)16 Partner (com.axelor.apps.base.db.Partner)15 IOException (java.io.IOException)13 BirtException (org.eclipse.birt.core.exception.BirtException)13 Invoice (com.axelor.apps.account.db.Invoice)12 List (java.util.List)12 Currency (com.axelor.apps.base.db.Currency)11 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 Product (com.axelor.apps.base.db.Product)8 StockMove (com.axelor.apps.stock.db.StockMove)8