Search in sources :

Example 21 with SaleOrder

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

the class SaleOrderCreateServiceSupplychainImpl method mergeSaleOrders.

@Transactional(rollbackOn = { Exception.class })
public SaleOrder mergeSaleOrders(List<SaleOrder> saleOrderList, Currency currency, Partner clientPartner, Company company, StockLocation stockLocation, 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, stockLocation, priceList, clientPartner, team, null);
    super.attachToNewSaleOrder(saleOrderList, saleOrderMerged);
    saleOrderComputeService.computeSaleOrder(saleOrderMerged);
    saleOrderRepository.save(saleOrderMerged);
    super.removeOldSaleOrders(saleOrderList);
    return saleOrderMerged;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Example 22 with SaleOrder

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

the class OpportunitySaleOrderSupplychainServiceImpl method createSaleOrderFromOpportunity.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder createSaleOrderFromOpportunity(Opportunity opportunity) throws AxelorException {
    SaleOrder saleOrder = super.createSaleOrderFromOpportunity(opportunity);
    // Set default invoiced and delivered partners and address in case of partner delegations
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getActivatePartnerRelations()) {
        Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(saleOrder);
    }
    saleOrderRepo.save(saleOrder);
    return saleOrder;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Example 23 with SaleOrder

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

the class InvoicePaymentToolServiceSupplychainImpl method updateAmountPaid.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateAmountPaid(Invoice invoice) throws AxelorException {
    super.updateAmountPaid(invoice);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return;
    }
    SaleOrder saleOrder = invoice.getSaleOrder();
    if (saleOrder != null) {
        // compute sale order totals
        Beans.get(SaleOrderComputeService.class)._computeSaleOrder(saleOrder);
    }
}
Also used : SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Example 24 with SaleOrder

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

the class AccountingSituationSupplychainServiceImpl method computeUsedCredit.

@Override
public AccountingSituation computeUsedCredit(AccountingSituation accountingSituation) throws AxelorException {
    BigDecimal sum = BigDecimal.ZERO;
    List<SaleOrder> saleOrderList = saleOrderRepository.all().filter("self.company = ?1 AND self.clientPartner = ?2 AND self.statusSelect > ?3 AND self.statusSelect < ?4", accountingSituation.getCompany(), accountingSituation.getPartner(), SaleOrderRepository.STATUS_DRAFT_QUOTATION, SaleOrderRepository.STATUS_CANCELED).fetch();
    for (SaleOrder saleOrder : saleOrderList) {
        sum = sum.add(saleOrder.getInTaxTotal().subtract(getInTaxInvoicedAmount(saleOrder)));
    }
    // invoice payments
    if (!accountConfigService.getAccountConfig(accountingSituation.getCompany()).getGenerateMoveForInvoicePayment()) {
        List<InvoicePayment> invoicePaymentList = invoicePaymentRepository.all().filter("self.invoice.company = :company" + " AND self.invoice.partner = :partner" + " AND self.statusSelect = :validated" + " AND self.typeSelect != :imputation").bind("company", accountingSituation.getCompany()).bind("partner", accountingSituation.getPartner()).bind("validated", InvoicePaymentRepository.STATUS_VALIDATED).bind("imputation", InvoicePaymentRepository.TYPE_ADV_PAYMENT_IMPUTATION).fetch();
        if (invoicePaymentList != null) {
            for (InvoicePayment invoicePayment : invoicePaymentList) {
                sum = sum.subtract(invoicePayment.getAmount());
            }
        }
    }
    sum = accountingSituation.getBalanceCustAccount().add(sum);
    accountingSituation.setUsedCredit(sum.setScale(2, RoundingMode.HALF_UP));
    return accountingSituation;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 25 with SaleOrder

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

the class SaleOrderProjectController method updateLines.

public void updateLines(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        saleOrder = Beans.get(ProjectAnalyticMoveLineService.class).updateLines(saleOrder);
        response.setValue("saleOrderLineList", saleOrder.getSaleOrderLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : 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