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);
}
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations