use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class MrpServiceImpl method createSaleForecastMrpLines.
@Transactional(rollbackOn = { Exception.class })
protected void createSaleForecastMrpLines(Mrp mrp, MrpForecast mrpForecast, MrpLineType saleForecastMrpLineType) throws AxelorException {
LocalDate maturityDate = mrpForecast.getForecastDate();
if (maturityDate != null && !maturityDate.isBefore(today) && this.isBeforeEndDate(maturityDate)) {
Unit unit = mrpForecast.getProduct().getUnit();
BigDecimal qty = mrpForecast.getQty();
if (!unit.equals(mrpForecast.getUnit())) {
qty = Beans.get(UnitConversionService.class).convert(mrpForecast.getUnit(), unit, qty, qty.scale(), mrpForecast.getProduct());
}
MrpLine mrpLine = this.createMrpLine(mrp, mrpForecast.getProduct(), saleForecastMrpLineType, qty, maturityDate, BigDecimal.ZERO, mrpForecast.getStockLocation(), mrpForecast);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class MrpServiceImpl method createPurchaseMrpLines.
@Transactional(rollbackOn = { Exception.class })
protected void createPurchaseMrpLines(Mrp mrp, PurchaseOrderLine purchaseOrderLine, MrpLineType purchaseOrderMrpLineType) throws AxelorException {
PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
LocalDate maturityDate = purchaseOrderLine.getEstimatedDelivDate();
if (maturityDate == null) {
maturityDate = purchaseOrder.getDeliveryDate();
}
if (maturityDate == null) {
maturityDate = purchaseOrderLine.getDesiredDelivDate();
}
maturityDate = this.computeMaturityDate(maturityDate, purchaseOrderMrpLineType);
if (this.isBeforeEndDate(maturityDate) || purchaseOrderMrpLineType.getIgnoreEndDate()) {
Unit unit = purchaseOrderLine.getProduct().getUnit();
BigDecimal qty = purchaseOrderLine.getQty().subtract(purchaseOrderLine.getReceivedQty());
if (!unit.equals(purchaseOrderLine.getUnit())) {
qty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), purchaseOrderLine.getProduct());
}
MrpLine mrpLine = this.createMrpLine(mrp, purchaseOrderLine.getProduct(), purchaseOrderMrpLineType, qty, maturityDate, BigDecimal.ZERO, purchaseOrder.getStockLocation(), purchaseOrderLine);
if (mrpLine != null) {
mrpLine.setSupplierPartner(purchaseOrder.getSupplierPartner());
mrpLineRepository.save(mrpLine);
}
}
}
use of com.axelor.apps.base.db.Unit 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);
}
}
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method getAvailableQty.
protected BigDecimal getAvailableQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
}
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
String query = stockLocationLineService.getAvailableStockForAProduct(product.getId(), companyId, stockLocationId);
List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
// Compute
BigDecimal sumAvailableQty = BigDecimal.ZERO;
if (!stockLocationLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (StockLocationLine stockLocationLine : stockLocationLineList) {
BigDecimal productAvailableQty = stockLocationLine.getCurrentQty();
unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, productAvailableQty, productAvailableQty.scale(), product);
sumAvailableQty = sumAvailableQty.add(productAvailableQty);
}
}
return sumAvailableQty;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method updateCostPrice.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateCostPrice(PurchaseOrder purchaseOrder) throws AxelorException {
if (purchaseOrder.getPurchaseOrderLineList() != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
Product product = purchaseOrderLine.getProduct();
if (product != null) {
BigDecimal lastPurchasePrice = (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()) ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice();
lastPurchasePrice = currencyService.getAmountCurrencyConvertedAtDate(purchaseOrder.getCurrency(), purchaseOrder.getCompany().getCurrency(), lastPurchasePrice, currencyService.getDateToConvert(null));
productCompanyService.set(product, "lastPurchasePrice", lastPurchasePrice, purchaseOrder.getCompany());
LocalDate lastPurchaseDate = Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
productCompanyService.set(product, "lastPurchaseDate", lastPurchaseDate, purchaseOrder.getCompany());
if ((Boolean) productCompanyService.get(product, "defShipCoefByPartner", purchaseOrder.getCompany())) {
Unit productPurchaseUnit = (Unit) productCompanyService.get(product, "purchasesUnit", purchaseOrder.getCompany());
productPurchaseUnit = productPurchaseUnit != null ? productPurchaseUnit : (Unit) productCompanyService.get(product, "unit", purchaseOrder.getCompany());
BigDecimal convertedQty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), productPurchaseUnit, purchaseOrderLine.getQty(), purchaseOrderLine.getQty().scale(), product);
BigDecimal shippingCoef = Beans.get(ShippingCoefService.class).getShippingCoefDefByPartner(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), convertedQty);
if (shippingCoef.compareTo(BigDecimal.ZERO) != 0) {
productCompanyService.set(product, "shippingCoef", shippingCoef, purchaseOrder.getCompany());
}
}
if ((Integer) productCompanyService.get(product, "costTypeSelect", purchaseOrder.getCompany()) == ProductRepository.COST_TYPE_LAST_PURCHASE_PRICE) {
productCompanyService.set(product, "costPrice", lastPurchasePrice, purchaseOrder.getCompany());
if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", purchaseOrder.getCompany())) {
Beans.get(ProductService.class).updateSalePrice(product, purchaseOrder.getCompany());
}
}
}
}
purchaseOrderRepo.save(purchaseOrder);
}
}
Aggregations