Search in sources :

Example 71 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method emptyLine.

public void emptyLine(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    if (saleOrderLine.getTypeSelect() != SaleOrderLineRepository.TYPE_NORMAL) {
        Map<String, Object> newSaleOrderLine = Mapper.toMap(new SaleOrderLine());
        newSaleOrderLine.put("qty", BigDecimal.ZERO);
        newSaleOrderLine.put("id", saleOrderLine.getId());
        newSaleOrderLine.put("version", saleOrderLine.getVersion());
        newSaleOrderLine.put("typeSelect", saleOrderLine.getTypeSelect());
        if (saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_END_OF_PACK) {
            newSaleOrderLine.put("productName", I18n.get(ITranslation.SALE_ORDER_LINE_END_OF_PACK));
        }
        response.setValues(newSaleOrderLine);
    }
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 72 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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 73 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method updatePrice.

/**
 * Update the ex. tax unit price of an invoice line from its in. tax unit price.
 *
 * @param request
 * @param response
 */
public void updatePrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    try {
        BigDecimal inTaxPrice = saleOrderLine.getInTaxPrice();
        TaxLine taxLine = saleOrderLine.getTaxLine();
        response.setValue("price", Beans.get(SaleOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 74 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineServiceImpl method createSaleOrderLine.

@Override
public SaleOrderLine createSaleOrderLine(PackLine packLine, SaleOrder saleOrder, BigDecimal packQty, BigDecimal conversionRate, Integer sequence) {
    if (packLine.getTypeSelect() == PackLineRepository.TYPE_START_OF_PACK || packLine.getTypeSelect() == PackLineRepository.TYPE_END_OF_PACK) {
        return createStartOfPackAndEndOfPackTypeSaleOrderLine(packLine.getPack(), saleOrder, packQty, packLine, packLine.getTypeSelect(), sequence);
    }
    if (packLine.getProductName() != null) {
        SaleOrderLine soLine = new SaleOrderLine();
        Product product = packLine.getProduct();
        soLine.setProduct(product);
        soLine.setProductName(packLine.getProductName());
        if (packLine.getQuantity() != null) {
            soLine.setQty(packLine.getQuantity().multiply(packQty).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP));
        }
        soLine.setUnit(packLine.getUnit());
        soLine.setTypeSelect(packLine.getTypeSelect());
        soLine.setSequence(sequence);
        if (packLine.getPrice() != null) {
            soLine.setPrice(packLine.getPrice().multiply(conversionRate));
        }
        if (product != null) {
            if (appSaleService.getAppSale().getIsEnabledProductDescriptionCopy()) {
                soLine.setDescription(product.getDescription());
            }
            try {
                this.fillPriceFromPackLine(soLine, saleOrder);
                this.computeValues(saleOrder, soLine);
            } catch (AxelorException e) {
                TraceBackService.trace(e);
            }
        }
        return soLine;
    }
    return null;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 75 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineTaxService method createsSaleOrderLineTax.

/**
 * Créer les lignes de TVA du devis. La création des lignes de TVA se basent sur les lignes de
 * devis ainsi que les sous-lignes de devis de celles-ci. Si une ligne de devis comporte des
 * sous-lignes de devis, alors on se base uniquement sur celles-ci.
 *
 * @param invoice La facture.
 * @param invoiceLines Les lignes de facture.
 * @param invoiceLineTaxes Les lignes des taxes de la facture.
 * @return La liste des lignes de taxe de la facture.
 */
public List<SaleOrderLineTax> createsSaleOrderLineTax(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLineList) {
    List<SaleOrderLineTax> saleOrderLineTaxList = new ArrayList<SaleOrderLineTax>();
    Map<TaxLine, SaleOrderLineTax> map = new HashMap<TaxLine, SaleOrderLineTax>();
    Set<String> specificNotes = new HashSet<String>();
    boolean customerSpecificNote = false;
    if (saleOrder.getClientPartner().getFiscalPosition() != null) {
        customerSpecificNote = saleOrder.getClientPartner().getFiscalPosition().getCustomerSpecificNote();
    }
    if (saleOrderLineList != null && !saleOrderLineList.isEmpty()) {
        LOG.debug("Création des lignes de tva pour les lignes de factures.");
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            TaxLine taxLine = saleOrderLine.getTaxLine();
            if (taxLine != null) {
                LOG.debug("Tax {}", taxLine);
                if (map.containsKey(taxLine)) {
                    SaleOrderLineTax saleOrderLineTax = map.get(taxLine);
                    saleOrderLineTax.setExTaxBase(saleOrderLineTax.getExTaxBase().add(saleOrderLine.getExTaxTotal()));
                } else {
                    SaleOrderLineTax saleOrderLineTax = new SaleOrderLineTax();
                    saleOrderLineTax.setSaleOrder(saleOrder);
                    saleOrderLineTax.setExTaxBase(saleOrderLine.getExTaxTotal());
                    saleOrderLineTax.setTaxLine(taxLine);
                    map.put(taxLine, saleOrderLineTax);
                }
            }
            if (!customerSpecificNote) {
                TaxEquiv taxEquiv = saleOrderLine.getTaxEquiv();
                if (taxEquiv != null && taxEquiv.getSpecificNote() != null) {
                    specificNotes.add(taxEquiv.getSpecificNote());
                }
            }
        }
    }
    for (SaleOrderLineTax saleOrderLineTax : map.values()) {
        // Dans la devise de la facture
        BigDecimal exTaxBase = saleOrderLineTax.getExTaxBase();
        BigDecimal taxTotal = BigDecimal.ZERO;
        if (saleOrderLineTax.getTaxLine() != null) {
            taxTotal = saleOrderToolService.computeAmount(exTaxBase, saleOrderLineTax.getTaxLine().getValue());
            saleOrderLineTax.setTaxTotal(taxTotal);
        }
        saleOrderLineTax.setInTaxTotal(exTaxBase.add(taxTotal));
        saleOrderLineTaxList.add(saleOrderLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { saleOrderLineTax.getTaxTotal(), saleOrderLineTax.getInTaxTotal() });
    }
    if (!customerSpecificNote) {
        saleOrder.setSpecificNotes(Joiner.on('\n').join(specificNotes));
    } else {
        saleOrder.setSpecificNotes(saleOrder.getClientPartner().getSpecificTaxNote());
    }
    return saleOrderLineTaxList;
}
Also used : SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) HashSet(java.util.HashSet)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6