use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method addLineToSaleOrder.
@Transactional(rollbackOn = { Exception.class })
@Override
public void addLineToSaleOrder(Configurator configurator, SaleOrder saleOrder, JsonContext jsonAttributes, JsonContext jsonIndicators) throws AxelorException {
SaleOrderLine saleOrderLine;
if (configurator.getConfiguratorCreator().getGenerateProduct()) {
// generate sale order line from product
saleOrderLine = new SaleOrderLine();
saleOrderLine.setSaleOrder(saleOrder);
generate(configurator, jsonAttributes, jsonIndicators);
saleOrderLine.setProduct(configurator.getProduct());
this.fillSaleOrderWithProduct(saleOrderLine);
Beans.get(SaleOrderLineService.class).computeValues(saleOrderLine.getSaleOrder(), saleOrderLine);
String qtyFormula = configurator.getConfiguratorCreator().getQtyFormula();
BigDecimal qty = BigDecimal.ONE;
if (qtyFormula != null && !"".equals(qtyFormula)) {
Object result = computeFormula(qtyFormula, jsonAttributes);
if (result != null) {
qty = new BigDecimal(result.toString());
}
}
saleOrderLine.setQty(qty);
Beans.get(SaleOrderLineRepository.class).save(saleOrderLine);
} else {
generateSaleOrderLine(configurator, jsonAttributes, jsonIndicators, saleOrder);
}
Beans.get(SaleOrderComputeService.class).computeSaleOrder(saleOrder);
Beans.get(SaleOrderRepository.class).save(saleOrder);
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method generateSaleOrderLine.
/**
* Create a sale order line from the configurator
*
* @param configurator
* @param jsonAttributes
* @param jsonIndicators
* @param saleOrder
* @return
*/
protected SaleOrderLine generateSaleOrderLine(Configurator configurator, JsonContext jsonAttributes, JsonContext jsonIndicators, SaleOrder saleOrder) throws AxelorException {
cleanIndicators(jsonIndicators);
SaleOrderLine saleOrderLine = Mapper.toBean(SaleOrderLine.class, jsonIndicators);
saleOrderLine.setSaleOrder(saleOrder);
fixRelationalFields(saleOrderLine);
fetchManyToManyFields(saleOrderLine);
fillOneToManyFields(configurator, saleOrderLine, jsonAttributes);
this.fillSaleOrderWithProduct(saleOrderLine);
this.overwriteFieldToUpdate(configurator, saleOrderLine, jsonAttributes);
if (saleOrderLine.getProductName() == null) {
throw new AxelorException(configurator, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CONFIGURATOR_SALE_ORDER_LINE_MISSING_PRODUCT_NAME));
}
saleOrderLine = Beans.get(SaleOrderLineRepository.class).save(saleOrderLine);
Beans.get(SaleOrderLineService.class).computeValues(saleOrderLine.getSaleOrder(), saleOrderLine);
return saleOrderLine;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderManagementRepository method copy.
@Override
public SaleOrder copy(SaleOrder entity, boolean deep) {
SaleOrder copy = super.copy(entity, deep);
copy.setStatusSelect(SaleOrderRepository.STATUS_DRAFT_QUOTATION);
copy.setSaleOrderSeq(null);
copy.clearBatchSet();
copy.setImportId(null);
copy.setCreationDate(Beans.get(AppBaseService.class).getTodayDate(entity.getCompany()));
copy.setConfirmationDateTime(null);
copy.setConfirmedByUser(null);
copy.setOrderDate(null);
copy.setOrderNumber(null);
copy.setVersionNumber(1);
copy.setTotalCostPrice(null);
copy.setTotalGrossMargin(null);
copy.setMarginRate(null);
copy.setEndOfValidityDate(null);
copy.setDeliveryDate(null);
copy.setOrderBeingEdited(false);
if (copy.getAdvancePaymentAmountNeeded().compareTo(copy.getAdvanceTotal()) <= 0) {
copy.setAdvancePaymentAmountNeeded(BigDecimal.ZERO);
copy.setAdvancePaymentNeeded(false);
copy.clearAdvancePaymentList();
}
if (copy.getSaleOrderLineList() != null) {
for (SaleOrderLine saleOrderLine : copy.getSaleOrderLineList()) {
saleOrderLine.setDesiredDelivDate(null);
saleOrderLine.setEstimatedDelivDate(null);
saleOrderLine.setDiscountDerogation(null);
}
}
return copy;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class ABCAnalysisServiceSaleImpl method createABCAnalysisLine.
@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
ABCAnalysisLine abcAnalysisLine = null;
BigDecimal productQty = BigDecimal.ZERO;
BigDecimal productWorth = BigDecimal.ZERO;
List<SaleOrderLine> saleOrderLineList;
int offset = 0;
Query<SaleOrderLine> saleOrderLineQuery = saleOrderLineRepository.all().filter("(self.saleOrder.statusSelect = :statusConfirmed OR self.saleOrder.statusSelect = :statusCompleted) AND self.saleOrder.confirmationDateTime >= :startDate AND self.saleOrder.confirmationDateTime <= :endDate AND self.product.id = :productId").bind("statusConfirmed", SaleOrderRepository.STATUS_ORDER_CONFIRMED).bind("statusCompleted", SaleOrderRepository.STATUS_ORDER_COMPLETED).bind("startDate", toLocalDateT(toDate(abcAnalysis.getStartDate()))).bind("endDate", toLocalDateT(toDate(abcAnalysis.getEndDate())).withHour(23).withMinute(59).withSecond(59)).bind("productId", product.getId()).order("id");
while (!(saleOrderLineList = saleOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += saleOrderLineList.size();
abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
if (abcAnalysisLine == null) {
abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
}
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
BigDecimal convertedQty = unitConversionService.convert(saleOrderLine.getUnit(), product.getUnit(), saleOrderLine.getQty(), 5, product);
productQty = productQty.add(convertedQty);
productWorth = productWorth.add(saleOrderLine.getCompanyExTaxTotal());
}
super.incTotalQty(productQty);
super.incTotalWorth(productWorth);
JPA.clear();
}
if (abcAnalysisLine != null) {
setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
}
return Optional.ofNullable(abcAnalysisLine);
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method createShippingCostLine.
@Override
public SaleOrderLine createShippingCostLine(SaleOrder saleOrder, Product shippingCostProduct) throws AxelorException {
SaleOrderLine shippingCostLine = new SaleOrderLine();
shippingCostLine.setSaleOrder(saleOrder);
shippingCostLine.setProduct(shippingCostProduct);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
saleOrderLineService.computeProductInformation(shippingCostLine, saleOrder);
saleOrderLineService.computeValues(saleOrder, shippingCostLine);
return shippingCostLine;
}
Aggregations