Search in sources :

Example 11 with TrackingNumber

use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.

the class ImportInventoryLine method importInventoryLine.

@Transactional(rollbackOn = { Exception.class })
public Object importInventoryLine(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof InventoryLine;
    InventoryLine inventoryLine = (InventoryLine) bean;
    TrackingNumberConfiguration trackingNumberConfig = inventoryLine.getProduct().getTrackingNumberConfiguration();
    BigDecimal qtyByTracking = BigDecimal.ONE;
    BigDecimal realQtyRemaning = inventoryLine.getRealQty();
    inventoryLineService.compute(inventoryLine, inventoryLine.getInventory());
    TrackingNumber trackingNumber;
    if (trackingNumberConfig != null) {
        if (trackingNumberConfig.getGenerateProductionAutoTrackingNbr()) {
            qtyByTracking = trackingNumberConfig.getProductionQtyByTracking();
        } else if (trackingNumberConfig.getGeneratePurchaseAutoTrackingNbr()) {
            qtyByTracking = trackingNumberConfig.getPurchaseQtyByTracking();
        } else {
            qtyByTracking = trackingNumberConfig.getSaleQtyByTracking();
        }
        InventoryLine inventoryLineNew;
        for (int i = 0; i < inventoryLine.getRealQty().intValue(); i += qtyByTracking.intValue()) {
            trackingNumber = trackingNumberService.createTrackingNumber(inventoryLine.getProduct(), inventoryLine.getInventory().getStockLocation().getCompany(), appBaseService.getTodayDate(inventoryLine.getInventory().getStockLocation().getCompany()), inventoryLine.getInventory().getInventorySeq());
            if (realQtyRemaning.compareTo(qtyByTracking) < 0) {
                trackingNumber.setCounter(realQtyRemaning);
            } else {
                trackingNumber.setCounter(qtyByTracking);
            }
            inventoryLineNew = inventoryLineService.createInventoryLine(inventoryLine.getInventory(), inventoryLine.getProduct(), inventoryLine.getCurrentQty(), inventoryLine.getRack(), trackingNumber);
            inventoryLineNew.setUnit(inventoryLine.getProduct().getUnit());
            if (realQtyRemaning.compareTo(qtyByTracking) < 0) {
                inventoryLineNew.setRealQty(realQtyRemaning);
            } else {
                inventoryLineNew.setRealQty(qtyByTracking);
                realQtyRemaning = realQtyRemaning.subtract(qtyByTracking);
            }
            inventoryLineRepo.save(inventoryLineNew);
        }
        return null;
    }
    return bean;
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) TrackingNumberConfiguration(com.axelor.apps.stock.db.TrackingNumberConfiguration) BigDecimal(java.math.BigDecimal) InventoryLine(com.axelor.apps.stock.db.InventoryLine) Transactional(com.google.inject.persist.Transactional)

Example 12 with TrackingNumber

use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.

the class TrackingNumberService method getTrackingNumber.

@Transactional(rollbackOn = { Exception.class })
public TrackingNumber getTrackingNumber(Product product, BigDecimal sizeOfLot, Company company, LocalDate date, String origin) throws AxelorException {
    TrackingNumber trackingNumber = trackingNumberRepo.all().filter("self.product = ?1 AND self.counter < ?2", product, sizeOfLot).fetchOne();
    if (trackingNumber == null) {
        trackingNumber = trackingNumberRepo.save(this.createTrackingNumber(product, company, date, origin));
    }
    trackingNumber.setCounter(trackingNumber.getCounter().add(sizeOfLot));
    return trackingNumber;
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Transactional(com.google.inject.persist.Transactional)

Example 13 with TrackingNumber

use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.

the class TrackingNumberService method createTrackingNumber.

public TrackingNumber createTrackingNumber(Product product, Company company, LocalDate date, String origin) throws AxelorException {
    Preconditions.checkNotNull(product, I18n.get("Product cannot be null."));
    Preconditions.checkNotNull(company, I18n.get("Company cannot be null."));
    if (date == null) {
        throw new AxelorException(product, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TRACK_NUMBER_DATE_MISSING), product.getFullName(), origin);
    }
    TrackingNumber trackingNumber = new TrackingNumber();
    if (product.getIsPerishable()) {
        trackingNumber.setPerishableExpirationDate(date.plusMonths(product.getPerishableNbrOfMonths()));
    }
    if (product.getHasWarranty()) {
        trackingNumber.setWarrantyExpirationDate(date.plusMonths(product.getWarrantyNbrOfMonths()));
    }
    trackingNumber.setProduct(product);
    trackingNumber.setCounter(BigDecimal.ZERO);
    TrackingNumberConfiguration trackingNumberConfiguration = product.getTrackingNumberConfiguration();
    if (trackingNumberConfiguration.getSequence() == null) {
        throw new AxelorException(product, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TRACKING_NUMBER_1), company.getName(), product.getCode());
    }
    Sequence sequence = trackingNumberConfiguration.getSequence();
    String seq;
    while (true) {
        seq = sequenceService.getSequenceNumber(sequence);
        if (trackingNumberRepo.all().filter("self.product = ?1 AND self.trackingNumberSeq = ?2", product, seq).count() == 0) {
            break;
        }
    }
    trackingNumber.setTrackingNumberSeq(seq);
    return trackingNumber;
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Sequence(com.axelor.apps.base.db.Sequence) TrackingNumberConfiguration(com.axelor.apps.stock.db.TrackingNumberConfiguration)

Aggregations

TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)13 BigDecimal (java.math.BigDecimal)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)6 Product (com.axelor.apps.base.db.Product)5 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)5 AxelorException (com.axelor.exception.AxelorException)5 StockLocation (com.axelor.apps.stock.db.StockLocation)4 Transactional (com.google.inject.persist.Transactional)4 InventoryLine (com.axelor.apps.stock.db.InventoryLine)3 StockMove (com.axelor.apps.stock.db.StockMove)2 TrackingNumberConfiguration (com.axelor.apps.stock.db.TrackingNumberConfiguration)2 Beans (com.axelor.inject.Beans)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AppSupplychain (com.axelor.apps.base.db.AppSupplychain)1 Company (com.axelor.apps.base.db.Company)1 Sequence (com.axelor.apps.base.db.Sequence)1 Wizard (com.axelor.apps.base.db.Wizard)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1