use of com.axelor.apps.purchase.db.SupplierCatalog in project axelor-open-suite by axelor.
the class CostSheetLineServiceImpl method getComponentCostPrice.
protected BigDecimal getComponentCostPrice(Product product, int componentsValuationMethod, Company company) throws AxelorException {
BigDecimal price = null;
Currency companyCurrency = company.getCurrency();
if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_AVERAGE) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
}
} else if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_COST) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
}
}
if (product.getPurchasable() && (price == null || price.compareTo(BigDecimal.ZERO) == 0)) {
price = (BigDecimal) productCompanyService.get(product, "purchasePrice", company);
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), price, appProductionService.getNbDecimalDigitForUnitPrice(), product);
BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, (Partner) productCompanyService.get(product, "defaultSupplierPartner", company), company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
if (productCompanyService.get(product, "purchaseCurrency", company) == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_PURCHASE_CURRENCY), product.getFullName());
}
price = currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), companyCurrency, price, appProductionService.getTodayDate(company));
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
@SuppressWarnings("unchecked") List<SupplierCatalog> supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
for (SupplierCatalog supplierCatalog : supplierCatalogList) {
if (BigDecimal.ZERO.compareTo(supplierCatalog.getPrice()) < 0) {
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), supplierCatalog.getPrice(), appProductionService.getNbDecimalDigitForUnitPrice(), product);
Partner supplierPartner = supplierCatalog.getSupplierPartner();
if (supplierPartner != null) {
shippingCoef = shippingCoefService.getShippingCoef(product, supplierPartner, company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
price = currencyService.getAmountCurrencyConvertedAtDate(supplierPartner.getCurrency(), companyCurrency, price, appProductionService.getTodayDate(company));
}
break;
}
}
}
}
return price;
}
use of com.axelor.apps.purchase.db.SupplierCatalog in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method getSupplierCatalog.
@Override
public SupplierCatalog getSupplierCatalog(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
SupplierCatalog supplierCatalog = supplierCatalogService.getSupplierCatalog(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany());
return supplierCatalog;
}
use of com.axelor.apps.purchase.db.SupplierCatalog in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method getProductSupplierInfos.
public String[] getProductSupplierInfos(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
String productName = "";
String productCode = "";
if (product == null) {
return new String[] { productName, productCode };
}
SupplierCatalog supplierCatalog = supplierCatalogService.getSupplierCatalog(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany());
if (supplierCatalog != null) {
productName = supplierCatalog.getProductSupplierName();
productCode = supplierCatalog.getProductSupplierCode();
}
return new String[] { Strings.isNullOrEmpty(productName) ? product.getName() : productName, Strings.isNullOrEmpty(productCode) ? product.getCode() : productCode };
}
use of com.axelor.apps.purchase.db.SupplierCatalog in project axelor-open-suite by axelor.
the class SupplierCatalogServiceImpl method updateInfoFromCatalog.
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> updateInfoFromCatalog(Product product, BigDecimal qty, Partner partner, Currency currency, LocalDate date, Company company) throws AxelorException {
Map<String, Object> info = null;
List<SupplierCatalog> supplierCatalogList = null;
if (appPurchaseService.getAppPurchase().getManageSupplierCatalog()) {
supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
}
if (supplierCatalogList != null && !supplierCatalogList.isEmpty()) {
SupplierCatalog supplierCatalog = Beans.get(SupplierCatalogRepository.class).all().filter("self.product = ?1 AND self.minQty <= ?2 AND self.supplierPartner = ?3 ORDER BY self.minQty DESC", product, qty, partner).fetchOne();
if (supplierCatalog != null) {
info = new HashMap<>();
info.put("price", currencyService.getAmountCurrencyConvertedAtDate(supplierCatalog.getSupplierPartner().getCurrency(), currency, supplierCatalog.getPrice(), date).setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP));
info.put("productName", supplierCatalog.getProductSupplierName());
info.put("productCode", supplierCatalog.getProductSupplierCode());
} else if (this.getSupplierCatalog(product, partner, company) != null) {
info = new HashMap<>();
info.put("price", currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), currency, (BigDecimal) productCompanyService.get(product, "purchasePrice", company), date).setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP));
info.put("productName", null);
info.put("productCode", null);
}
}
return info;
}
use of com.axelor.apps.purchase.db.SupplierCatalog in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method getUnitPrice.
/**
* A function used to get the unit price of a purchase order line, either in ati or wt
*
* @param purchaseOrder the purchase order containing the purchase order line
* @param purchaseOrderLine
* @param taxLine the tax applied to the unit price
* @param resultInAti whether or not you want the result to be in ati
* @return the unit price of the purchase order line or null if the product is not available for
* purchase at the supplier of the purchase order
* @throws AxelorException
*/
private BigDecimal getUnitPrice(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, TaxLine taxLine, boolean resultInAti) throws AxelorException {
BigDecimal purchasePrice = new BigDecimal(0);
Currency purchaseCurrency = null;
Product product = purchaseOrderLine.getProduct();
SupplierCatalog supplierCatalog = supplierCatalogService.getSupplierCatalog(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany());
if (supplierCatalog != null) {
purchasePrice = supplierCatalog.getPrice();
purchaseCurrency = supplierCatalog.getSupplierPartner().getCurrency();
} else {
if (product != null) {
purchasePrice = (BigDecimal) productCompanyService.get(product, "purchasePrice", purchaseOrder.getCompany());
purchaseCurrency = (Currency) productCompanyService.get(product, "purchaseCurrency", purchaseOrder.getCompany());
}
}
Boolean inAti = (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany());
BigDecimal price = (inAti == resultInAti) ? purchasePrice : this.convertUnitPrice(inAti, taxLine, purchasePrice);
return currencyService.getAmountCurrencyConvertedAtDate(purchaseCurrency, purchaseOrder.getCurrency(), price, purchaseOrder.getOrderDate()).setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Aggregations