Search in sources :

Example 91 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class DeclarationOfExchangesExporterGoods method exportLineToCsv.

protected String[] exportLineToCsv(StockMoveLine stockMoveLine, int lineNum) throws AxelorException {
    String[] data = new String[columnHeadersList.size()];
    StockMove stockMove = stockMoveLine.getStockMove();
    String customsCode = stockMoveLine.getCustomsCode();
    Product product = stockMoveLine.getProduct();
    if (StringUtils.isBlank(customsCode)) {
        if (product == null) {
            customsCode = I18n.get("Product is missing.");
        }
        if (product != null && product.getCustomsCodeNomenclature() != null) {
            customsCode = product.getCustomsCodeNomenclature().getCode();
        }
        if (StringUtils.isBlank(customsCode)) {
            customsCode = String.format(I18n.get("Customs code nomenclature is missing on product %s."), product.getCode());
        }
    }
    BigDecimal fiscalValue = stockMoveLine.getCompanyUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
    // Only positive fiscal value should be take into account
    if (fiscalValue.compareTo(BigDecimal.ZERO) <= 0) {
        return new String[0];
    }
    Regime regime = stockMoveLine.getRegime();
    if (regime == null) {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
            regime = Regime.EXONERATED_SHIPMENT_AND_TRANSFER;
        } else if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            regime = Regime.INTRACOMMUNITY_ACQUISITION_TAXABLE_IN_FRANCE;
        }
    }
    BigDecimal totalNetMass = stockMoveLine.getTotalNetMass().setScale(0, RoundingMode.HALF_UP);
    BigInteger supplementaryUnit = stockMoveLine.getRealQty().setScale(0, RoundingMode.CEILING).toBigInteger();
    NatureOfTransaction natTrans = stockMoveLine.getNatureOfTransaction();
    if (natTrans == null) {
        natTrans = stockMove.getIsReversion() ? NatureOfTransaction.RETURN_OF_GOODS : NatureOfTransaction.FIRM_PURCHASE_OR_SALE;
    }
    ModeOfTransport modeOfTransport = stockMove.getModeOfTransport();
    if (modeOfTransport == null) {
        modeOfTransport = ModeOfTransport.CONSIGNMENTS_BY_POST;
    }
    String srcDstCountry;
    String dept;
    try {
        Address partnerAddress = stockMoveToolService.getPartnerAddress(stockMoveLine.getStockMove());
        srcDstCountry = partnerAddress.getAddressL7Country().getAlpha2Code();
    } catch (AxelorException e) {
        srcDstCountry = e.getMessage();
    }
    try {
        Address companyAddress = stockMoveToolService.getCompanyAddress(stockMoveLine.getStockMove());
        dept = companyAddress.getCity().getDepartment().getCode();
    } catch (AxelorException e) {
        dept = e.getMessage();
    }
    String countryOrigCode;
    if (stockMoveLine.getCountryOfOrigin() != null) {
        countryOrigCode = stockMoveLine.getCountryOfOrigin().getAlpha2Code();
    } else {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            countryOrigCode = srcDstCountry;
        } else {
            countryOrigCode = "";
        }
    }
    String taxNbr;
    if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
        if (stockMove.getPartner() == null) {
            taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
        } else if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
            taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
        } else {
            taxNbr = stockMove.getPartner().getTaxNbr();
        }
    } else {
        taxNbr = "";
    }
    String partnerSeq = "";
    if (stockMove.getPartner() != null) {
        partnerSeq = stockMove.getPartner().getPartnerSeq();
    }
    String productCode = "";
    String productName = "";
    if (product != null) {
        productCode = product.getCode();
        productName = product.getName();
    }
    String invoiceId = "";
    Set<Invoice> invoiceSet = stockMove.getInvoiceSet();
    if (invoiceSet != null) {
        for (Invoice invoice : invoiceSet) {
            if (invoice.getStatusSelect() == InvoiceRepository.STATUS_VENTILATED) {
                invoiceId += invoice.getInvoiceId() + "|";
            }
        }
        if (invoiceId != null && !invoiceId.isEmpty()) {
            invoiceId = invoiceId.substring(0, invoiceId.length() - 1);
        }
    }
    data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum);
    data[columnHeadersList.indexOf(NOMENCLATURE)] = customsCode;
    data[columnHeadersList.indexOf(SRC_DST_COUNTRY)] = srcDstCountry;
    data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
    data[columnHeadersList.indexOf(REGIME)] = String.valueOf(regime.getValue());
    data[columnHeadersList.indexOf(MASS)] = String.valueOf(totalNetMass);
    data[columnHeadersList.indexOf(UNITS)] = String.valueOf(supplementaryUnit);
    data[columnHeadersList.indexOf(NAT_TRANS)] = String.valueOf(natTrans.getValue());
    data[columnHeadersList.indexOf(TRANSP)] = String.valueOf(modeOfTransport.getValue());
    data[columnHeadersList.indexOf(DEPT)] = dept;
    data[columnHeadersList.indexOf(COUNTRY_ORIG)] = countryOrigCode;
    data[columnHeadersList.indexOf(ACQUIRER)] = taxNbr;
    data[columnHeadersList.indexOf(PRODUCT_CODE)] = productCode;
    data[columnHeadersList.indexOf(PRODUCT_NAME)] = productName;
    data[columnHeadersList.indexOf(PARTNER_SEQ)] = partnerSeq;
    data[columnHeadersList.indexOf(INVOICE)] = invoiceId;
    return data;
}
Also used : Regime(com.axelor.apps.stock.db.Regime) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) Product(com.axelor.apps.base.db.Product) NatureOfTransaction(com.axelor.apps.stock.db.NatureOfTransaction) BigDecimal(java.math.BigDecimal) ModeOfTransport(com.axelor.apps.stock.db.ModeOfTransport) BigInteger(java.math.BigInteger)

Example 92 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class StockLocationServiceSupplychainImpl method getReservedQty.

@Override
public BigDecimal getReservedQty(Long productId, Long locationId, Long companyId) throws AxelorException {
    if (productId != null) {
        Product product = productRepo.find(productId);
        Unit productUnit = product.getUnit();
        UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
        if (locationId == null || locationId == 0L) {
            List<StockLocation> stockLocations = getNonVirtualStockLocations(companyId);
            if (!stockLocations.isEmpty()) {
                BigDecimal reservedQty = BigDecimal.ZERO;
                for (StockLocation stockLocation : stockLocations) {
                    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockLocationRepo.find(stockLocation.getId()), productRepo.find(productId));
                    if (stockLocationLine != null) {
                        Unit stockLocationLineUnit = stockLocationLine.getUnit();
                        reservedQty = reservedQty.add(stockLocationLine.getReservedQty());
                        if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                            reservedQty = unitConversionService.convert(stockLocationLineUnit, productUnit, reservedQty, reservedQty.scale(), product);
                        }
                    }
                }
                return reservedQty;
            }
        } else {
            StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockLocationRepo.find(locationId), productRepo.find(productId));
            if (stockLocationLine != null) {
                Unit stockLocationLineUnit = stockLocationLine.getUnit();
                if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                    return unitConversionService.convert(stockLocationLineUnit, productUnit, stockLocationLine.getReservedQty(), stockLocationLine.getReservedQty().scale(), product);
                }
                return stockLocationLine.getReservedQty();
            }
        }
    }
    return BigDecimal.ZERO;
}
Also used : UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 93 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class InvoiceLineController method getFixedAssetCategory.

public void getFixedAssetCategory(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    Product product = invoiceLine.getProduct();
    if (invoice == null || product == null) {
        return;
    }
    FixedAssetCategory fixedAssetCategory = null;
    if (!product.getAccountManagementList().isEmpty() && (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND)) {
        Optional<AccountManagement> optionalFixedAssetCategory = product.getAccountManagementList().stream().filter(am -> invoice.getCompany().equals(am.getCompany())).findFirst();
        fixedAssetCategory = optionalFixedAssetCategory.isPresent() ? optionalFixedAssetCategory.get().getFixedAssetCategory() : null;
    }
    response.setValue("fixedAssetCategory", fixedAssetCategory);
}
Also used : Context(com.axelor.rpc.Context) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) HashMap(java.util.HashMap) AccountManagementServiceAccountImpl(com.axelor.apps.account.service.AccountManagementServiceAccountImpl) Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AccountTypeRepository(com.axelor.apps.account.db.repo.AccountTypeRepository) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxLine(com.axelor.apps.account.db.TaxLine) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) ActionRequest(com.axelor.rpc.ActionRequest) AccountManagement(com.axelor.apps.account.db.AccountManagement) InvoiceLineManagement(com.axelor.apps.account.service.invoice.generator.line.InvoiceLineManagement) ITranslation(com.axelor.apps.account.translation.ITranslation) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Entry(java.util.Map.Entry) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 94 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class InvoiceLineController method getAccount.

public void getAccount(ActionRequest request, ActionResponse response) {
    try {
        InvoiceLine invoiceLine = request.getContext().asType(InvoiceLine.class);
        if (invoiceLine != null) {
            Product product = invoiceLine.getProduct();
            Invoice invoice = this.getInvoice(request.getContext());
            if (product != null) {
                Account account = Beans.get(AccountManagementServiceAccountImpl.class).getProductAccount(product, invoice.getCompany(), invoice.getPartner().getFiscalPosition(), InvoiceToolService.isPurchase(invoice), invoiceLine.getFixedAssets());
                response.setValue("account", account);
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AccountManagementServiceAccountImpl(com.axelor.apps.account.service.AccountManagementServiceAccountImpl) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 95 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProductController method generateProductVariants.

public void generateProductVariants(ActionRequest request, ActionResponse response) throws AxelorException {
    Product product = request.getContext().asType(Product.class);
    product = Beans.get(ProductRepository.class).find(product.getId());
    if (product.getProductVariantConfig() != null) {
        Beans.get(ProductService.class).generateProductVariants(product);
        response.setFlash(I18n.get(IExceptionMessage.PRODUCT_1));
        response.setReload(true);
    }
}
Also used : ProductService(com.axelor.apps.base.service.ProductService) Product(com.axelor.apps.base.db.Product)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16