use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class TestSaleOrderStockService method testUpdateDeliveryStatePartiallyDelivered2SaleOrder.
@Test
public void testUpdateDeliveryStatePartiallyDelivered2SaleOrder() throws AxelorException {
SaleOrder saleOrder = new SaleOrder();
SaleOrderLine saleOrderLine1 = new SaleOrderLine();
SaleOrderLine saleOrderLine2 = new SaleOrderLine();
saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_NOT_DELIVERED);
saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
saleOrder.addSaleOrderLineListItem(saleOrderLine1);
saleOrder.addSaleOrderLineListItem(saleOrderLine2);
saleOrderStockService.updateDeliveryState(saleOrder);
Assert.assertEquals(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED, (int) saleOrder.getDeliveryState());
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineSupplychainRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
Long saleOrderLineId = (Long) json.get("id");
SaleOrderLine saleOrderLine = find(saleOrderLineId);
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (this.availabilityIsNotManaged(saleOrderLine, saleOrder)) {
return super.populate(json, context);
}
BigDecimal availableStock = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getAvailableStock(saleOrder, saleOrderLine);
BigDecimal allocatedStock = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getAllocatedStock(saleOrder, saleOrderLine);
BigDecimal availableQty = availableStock.add(allocatedStock);
BigDecimal realQty = saleOrderLine.getQty();
if (availableQty.compareTo(realQty) >= 0) {
saleOrderLine.setAvailableStatus(I18n.get("Available"));
saleOrderLine.setAvailableStatusSelect(SaleOrderLineRepository.STATUS_AVAILABLE);
} else if (availableQty.compareTo(realQty) < 0) {
saleOrderLine.setAvailableStatus(I18n.get("Missing") + " (" + availableQty.subtract(realQty) + ")");
saleOrderLine.setAvailableStatusSelect(SaleOrderLineRepository.STATUS_MISSING);
}
json.put("availableStatus", saleOrderLine.getAvailableStatus());
json.put("availableStatusSelect", saleOrderLine.getAvailableStatusSelect());
return super.populate(json, context);
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class ProjectBusinessServiceImpl method generateQuotation.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateQuotation(Project project) throws AxelorException {
SaleOrder order = Beans.get(SaleOrderCreateService.class).createSaleOrder(project.getCompany());
Partner clientPartner = project.getClientPartner();
Partner contactPartner = project.getContactPartner();
if (contactPartner == null && clientPartner.getContactPartnerSet().size() == 1) {
contactPartner = clientPartner.getContactPartnerSet().iterator().next();
}
Company company = project.getCompany();
order.setProject(projectRepo.find(project.getId()));
order.setClientPartner(clientPartner);
order.setContactPartner(contactPartner);
order.setCompany(company);
order.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
order.setMainInvoicingAddressStr(addressService.computeAddressStr(order.getMainInvoicingAddress()));
order.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
order.setDeliveryAddressStr(addressService.computeAddressStr(order.getDeliveryAddress()));
order.setIsNeedingConformityCertificate(clientPartner.getIsNeedingConformityCertificate());
order.setCompanyBankDetails(Beans.get(AccountingSituationService.class).getCompanySalesBankDetails(company, clientPartner));
if (project.getCurrency() != null) {
order.setCurrency(project.getCurrency());
} else if (clientPartner.getCurrency() != null) {
order.setCurrency(clientPartner.getCurrency());
} else {
order.setCurrency(company.getCurrency());
}
if (project.getPriceList() != null) {
order.setPriceList(project.getPriceList());
} else {
order.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE));
}
if (order.getPriceList() != null) {
order.setHideDiscount(order.getPriceList().getHideDiscount());
}
if (clientPartner.getPaymentCondition() != null) {
order.setPaymentCondition(clientPartner.getPaymentCondition());
} else {
if (company != null && company.getAccountConfig() != null) {
order.setPaymentCondition(company.getAccountConfig().getDefPaymentCondition());
}
}
if (clientPartner.getInPaymentMode() != null) {
order.setPaymentMode(clientPartner.getInPaymentMode());
} else {
if (company != null && company.getAccountConfig() != null) {
order.setPaymentMode(company.getAccountConfig().getInPaymentMode());
}
}
AppSupplychain appSupplychain = Beans.get(AppSupplychainService.class).getAppSupplychain();
if (appSupplychain != null) {
order.setShipmentMode(clientPartner.getShipmentMode());
order.setFreightCarrierMode(clientPartner.getFreightCarrierMode());
if (clientPartner.getFreightCarrierMode() != null) {
order.setCarrierPartner(clientPartner.getFreightCarrierMode().getCarrierPartner());
}
Boolean interco = appSupplychain.getIntercoFromSale() && !order.getCreatedByInterco() && clientPartner != null && Beans.get(CompanyRepository.class).all().filter("self.partner = ?", clientPartner).fetchOne() != null;
order.setInterco(interco);
// Automatic invoiced and delivered partners set in case of partner delegations
if (appSupplychain.getActivatePartnerRelations()) {
Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(order);
}
}
return Beans.get(SaleOrderRepository.class).save(order);
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method setDefaultInvoicedAndDeliveredPartners.
protected void setDefaultInvoicedAndDeliveredPartners(SaleOrder saleOrder, Partner clientPartner) {
if (!CollectionUtils.isEmpty(clientPartner.getPartner1SupplychainLinkList())) {
List<PartnerSupplychainLink> partnerSupplychainLinkList = clientPartner.getPartner1SupplychainLinkList();
// Retrieve all Invoiced by Type
List<PartnerSupplychainLink> partnerSupplychainLinkInvoicedByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
// Retrieve all Delivered by Type
List<PartnerSupplychainLink> partnerSupplychainLinkDeliveredByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_DELIVERED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
// If there is only one, then it is the default one
if (partnerSupplychainLinkInvoicedByList.size() == 1) {
PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
saleOrder.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
} else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
saleOrder.setInvoicedPartner(clientPartner);
} else {
saleOrder.setInvoicedPartner(null);
}
if (partnerSupplychainLinkDeliveredByList.size() == 1) {
PartnerSupplychainLink partnerSupplychainLinkDeliveredBy = partnerSupplychainLinkDeliveredByList.get(0);
saleOrder.setDeliveredPartner(partnerSupplychainLinkDeliveredBy.getPartner2());
} else if (partnerSupplychainLinkDeliveredByList.size() == 0) {
saleOrder.setDeliveredPartner(clientPartner);
} else {
saleOrder.setDeliveredPartner(null);
}
} else {
saleOrder.setInvoicedPartner(clientPartner);
saleOrder.setDeliveredPartner(clientPartner);
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStocksMovesFromSaleOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public List<Long> createStocksMovesFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
if (!this.isSaleOrderWithProductsToDeliver(saleOrder)) {
return null;
}
if (saleOrder.getStockLocation() == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_MISSING_STOCK_LOCATION), saleOrder.getSaleOrderSeq());
}
List<Long> stockMoveList = new ArrayList<>();
Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = getAllSaleOrderLinePerDate(saleOrder);
for (LocalDate estimatedDeliveryDate : saleOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
List<SaleOrderLine> saleOrderLineList = saleOrderLinePerDateMap.get(estimatedDeliveryDate);
Optional<StockMove> stockMove = createStockMove(saleOrder, estimatedDeliveryDate, saleOrderLineList);
stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
}
Optional<List<SaleOrderLine>> saleOrderLineList = Optional.ofNullable(saleOrderLinePerDateMap.get(null));
if (saleOrderLineList.isPresent()) {
Optional<StockMove> stockMove = createStockMove(saleOrder, null, saleOrderLineList.get());
stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
}
return stockMoveList;
}
Aggregations