Search in sources :

Example 66 with SaleOrder

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

the class BatchInvoicing method process.

@Override
protected void process() {
    List<SaleOrder> saleOrders = subscriptionInvoiceService.getSubscriptionOrders(FETCH_LIMIT);
    while (!saleOrders.isEmpty()) {
        for (SaleOrder saleOrder : saleOrders) {
            try {
                subscriptionInvoiceService.generateSubscriptionInvoice(saleOrder);
                updateSaleOrder(saleOrder);
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Order %s"), saleOrder.getSaleOrderSeq()), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Order %s"), saleOrder.getSaleOrderSeq()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                LOG.error("Bug(Anomalie) généré(e) pour le devis {}", saleOrder.getSaleOrderSeq());
            }
        }
        JPA.clear();
        saleOrders = subscriptionInvoiceService.getSubscriptionOrders(FETCH_LIMIT);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 67 with SaleOrder

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

the class IntercoServiceImpl method generateIntercoSaleFromPurchase.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
    SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
    SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
    Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
    // create sale order
    SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
    // in ati
    saleOrder.setInAti(purchaseOrder.getInAti());
    // copy date
    saleOrder.setOrderDate(purchaseOrder.getOrderDate());
    // copy payments
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
    saleOrder.setPaymentMode(intercoPaymentMode);
    saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
    // copy delivery info
    saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
    saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
    saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
    // get stock location
    saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
    // copy timetable info
    saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
    saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
    // create lines
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
        }
    }
    saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
    // compute the sale order
    saleOrderComputeService.computeSaleOrder(saleOrder);
    saleOrder.setCreatedByInterco(true);
    Beans.get(SaleOrderRepository.class).save(saleOrder);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
        Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
    }
    purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
    saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
    return saleOrder;
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 68 with SaleOrder

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

the class AccountingCutOffServiceImpl method generateCutOffMove.

public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
    if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
        return null;
    }
    Company company = stockMove.getCompany();
    AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
    Partner partner = stockMove.getPartner();
    Account partnerAccount = null;
    Currency currency = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
        currency = saleOrder.getCurrency();
        if (partner == null) {
            partner = saleOrder.getClientPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
    }
    if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        currency = purchaseOrder.getCurrency();
        if (partner == null) {
            partner = purchaseOrder.getSupplierPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
    }
    String origin = stockMove.getStockMoveSeq();
    Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
    counter = 0;
    this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
    this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
        move.setStockMove(stockMove);
        moveValidateService.validate(move);
    } else {
        moveRepository.remove(move);
        return null;
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 69 with SaleOrder

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

the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.

@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
    SaleOrder saleOrder = advancePayment.getSaleOrder();
    Company company = saleOrder.getCompany();
    PaymentMode paymentMode = advancePayment.getPaymentMode();
    Partner clientPartner = saleOrder.getClientPartner();
    LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
    BankDetails bankDetails = saleOrder.getCompanyBankDetails();
    String ref = saleOrder.getSaleOrderSeq();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
    Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
    moveService.getMoveValidateService().validate(move);
    advancePayment.setMove(move);
    advancePaymentRepository.save(advancePayment);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 70 with SaleOrder

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

the class MrpServiceImpl method createSaleOrderMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createSaleOrderMrpLines(Mrp mrp, SaleOrderLine saleOrderLine, MrpLineType saleOrderMrpLineType, List<Integer> statusList) throws AxelorException {
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (!this.stockLocationList.contains(saleOrder.getStockLocation())) {
        return;
    }
    if (!statusList.contains(saleOrder.getStatusSelect())) {
        return;
    }
    if (saleOrderLine.getDeliveryState() == SaleOrderLineRepository.DELIVERY_STATE_DELIVERED) {
        return;
    }
    LocalDate maturityDate = saleOrderLine.getEstimatedDelivDate();
    if (maturityDate == null) {
        maturityDate = saleOrder.getDeliveryDate();
    }
    if (maturityDate == null) {
        maturityDate = saleOrderLine.getDesiredDelivDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, saleOrderMrpLineType);
    if (this.isBeforeEndDate(maturityDate)) {
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal qty = saleOrderLine.getQty().subtract(saleOrderLine.getDeliveredQty());
        if (!unit.equals(saleOrderLine.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(saleOrderLine.getUnit(), unit, qty, saleOrderLine.getQty().scale(), saleOrderLine.getProduct());
        }
        MrpLine mrpLine = this.createMrpLine(mrp, saleOrderLine.getProduct(), saleOrderMrpLineType, qty, maturityDate, BigDecimal.ZERO, saleOrder.getStockLocation(), saleOrderLine);
        if (mrpLine != null) {
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

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