use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class PurchaseProductServiceImpl method getLastShippingCoef.
@Override
public BigDecimal getLastShippingCoef(Product product) throws AxelorException {
PurchaseOrderLine lastPurchaseOrderLine = Beans.get(PurchaseOrderLineRepository.class).all().filter("self.product.id = :productId " + "AND (self.purchaseOrder.statusSelect = :validated " + "OR self.purchaseOrder.statusSelect = :finished)").bind("productId", product.getId()).bind("validated", PurchaseOrderRepository.STATUS_VALIDATED).bind("finished", PurchaseOrderRepository.STATUS_FINISHED).order("-purchaseOrder.validationDate").fetchOne();
if (lastPurchaseOrderLine != null) {
Partner partner = lastPurchaseOrderLine.getPurchaseOrder().getSupplierPartner();
Company company = lastPurchaseOrderLine.getPurchaseOrder().getCompany();
Unit productUnit = Beans.get(PurchaseOrderLineService.class).getPurchaseUnit(lastPurchaseOrderLine);
BigDecimal qty = Beans.get(UnitConversionService.class).convert(lastPurchaseOrderLine.getUnit(), productUnit, lastPurchaseOrderLine.getQty(), lastPurchaseOrderLine.getQty().scale(), product);
return Beans.get(ShippingCoefService.class).getShippingCoef(product, partner, company, qty);
} else {
return BigDecimal.ONE;
}
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStockMoveLine.
@Override
public StockMoveLine createStockMoveLine(StockMove stockMove, SaleOrderLine saleOrderLine, BigDecimal qty) throws AxelorException {
if (this.isStockMoveProduct(saleOrderLine)) {
Unit unit = saleOrderLine.getProduct().getUnit();
BigDecimal priceDiscounted = saleOrderLine.getPriceDiscounted();
BigDecimal requestedReservedQty = saleOrderLine.getRequestedReservedQty().subtract(saleOrderLine.getDeliveredQty());
BigDecimal companyUnitPriceUntaxed = (BigDecimal) productCompanyService.get(saleOrderLine.getProduct(), "costPrice", saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getCompany() : null);
if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
priceDiscounted = unitConversionService.convert(unit, saleOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), saleOrderLine.getProduct());
requestedReservedQty = unitConversionService.convert(saleOrderLine.getUnit(), unit, requestedReservedQty, requestedReservedQty.scale(), saleOrderLine.getProduct());
}
BigDecimal taxRate = BigDecimal.ZERO;
TaxLine taxLine = saleOrderLine.getTaxLine();
if (taxLine != null) {
taxRate = taxLine.getValue();
}
if (saleOrderLine.getQty().signum() != 0) {
companyUnitPriceUntaxed = saleOrderLine.getCompanyExTaxTotal().divide(saleOrderLine.getQty(), Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
StockMoveLine stockMoveLine = stockMoveLineSupplychainService.createStockMoveLine(saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), qty, requestedReservedQty, priceDiscounted, companyUnitPriceUntaxed, null, unit, stockMove, StockMoveLineService.TYPE_SALES, saleOrderLine.getSaleOrder().getInAti(), taxRate, saleOrderLine, null);
if (saleOrderLine.getDeliveryState() == 0) {
saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
}
return stockMoveLine;
}
return null;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method computeFromOrder.
protected StockMoveLine computeFromOrder(StockMoveLine stockMoveLine, StockMove stockMove) throws AxelorException {
BigDecimal unitPriceUntaxed = stockMoveLine.getUnitPriceUntaxed();
BigDecimal unitPriceTaxed = stockMoveLine.getUnitPriceTaxed();
Unit orderUnit = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine == null) {
// log the exception
TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_SALE_ORDER, stockMove.getOriginId(), stockMove.getName()));
} else {
unitPriceUntaxed = saleOrderLine.getPriceDiscounted();
unitPriceTaxed = saleOrderLine.getInTaxPrice();
orderUnit = saleOrderLine.getUnit();
}
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
if (purchaseOrderLine == null) {
// log the exception
TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_PURCHASE_ORDER, stockMove.getOriginId(), stockMove.getName()));
} else {
unitPriceUntaxed = purchaseOrderLine.getPrice();
unitPriceTaxed = purchaseOrderLine.getInTaxPrice();
orderUnit = purchaseOrderLine.getUnit();
}
}
stockMoveLine.setUnitPriceUntaxed(unitPriceUntaxed);
stockMoveLine.setUnitPriceTaxed(unitPriceTaxed);
Unit stockUnit = getStockUnit(stockMoveLine);
return convertUnitPrice(stockMoveLine, orderUnit, stockUnit);
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.
@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
return null;
}
if (stockMoveLineList.size() == 1) {
return stockMoveLineList.get(0);
}
StockMove stockMove = stockMoveLineList.get(0).getStockMove();
SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
Product product;
String productName;
String description;
BigDecimal quantity = BigDecimal.ZERO;
Unit unit;
if (saleOrderLine != null) {
product = saleOrderLine.getProduct();
productName = saleOrderLine.getProductName();
description = saleOrderLine.getDescription();
unit = saleOrderLine.getUnit();
} else if (purchaseOrderLine != null) {
product = purchaseOrderLine.getProduct();
productName = purchaseOrderLine.getProductName();
description = purchaseOrderLine.getDescription();
unit = purchaseOrderLine.getUnit();
} else {
// shouldn't ever happen or you misused this function
return null;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
quantity = quantity.add(stockMoveLine.getRealQty());
}
StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
generatedStockMoveLine.setIsMergedStockMoveLine(true);
return generatedStockMoveLine;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProjectGeneratorFactoryTaskTemplate method updateTask.
private void updateTask(ProjectTask root, ProjectTask childTask, SaleOrderLine orderLine) throws AxelorException {
childTask.setParentTask(root);
childTask.setQuantity(orderLine.getQty());
Product product = orderLine.getProduct();
childTask.setProduct(product);
childTask.setExTaxTotal(orderLine.getExTaxTotal());
Company company = orderLine.getSaleOrder() != null ? orderLine.getSaleOrder().getCompany() : null;
childTask.setUnitPrice(product != null ? (BigDecimal) productCompanyService.get(product, "salePrice", company) : null);
childTask.setUnit(product != null ? (Unit) productCompanyService.get(product, "unit", company) : null);
childTask.setSaleOrderLine(orderLine);
if (orderLine.getSaleOrder().getToInvoiceViaTask()) {
childTask.setToInvoice(true);
childTask.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
}
}
Aggregations