Set dynamic decimal digits for Sale WorkFlow
This commit is contained in:
@@ -160,13 +160,13 @@ public class PriceListService {
|
||||
if (discountTypeSelect == PriceListLineRepository.AMOUNT_TYPE_FIXED) {
|
||||
return unitPrice
|
||||
.subtract(discountAmount)
|
||||
.setScale(5, RoundingMode.HALF_UP);
|
||||
.setScale(appBaseService.getNbDecimalDigitForSalePrice(), RoundingMode.HALF_UP);
|
||||
} else if (discountTypeSelect == PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
|
||||
return unitPrice
|
||||
.multiply(new BigDecimal(100).subtract(discountAmount))
|
||||
.divide(
|
||||
new BigDecimal(100),
|
||||
5,
|
||||
appBaseService.getNbDecimalDigitForSalePrice(),
|
||||
RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,4 +74,6 @@ public interface AppBaseService extends AppService {
|
||||
* @param manageMultiBanks the new value for the manageMultiBanks boolean
|
||||
*/
|
||||
void setManageMultiBanks(boolean manageMultiBanks);
|
||||
|
||||
public int getNbDecimalDigitForSalePrice();
|
||||
}
|
||||
|
||||
@@ -104,6 +104,18 @@ public class AppBaseServiceImpl extends AppServiceImpl implements AppBaseService
|
||||
return DEFAULT_NB_DECIMAL_DIGITS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNbDecimalDigitForSalePrice() {
|
||||
|
||||
AppBase appBase = getAppBase();
|
||||
|
||||
if (appBase != null) {
|
||||
return appBase.getNbDecimalDigitForSalePrice();
|
||||
}
|
||||
|
||||
return DEFAULT_NB_DECIMAL_DIGITS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultPartnerLanguageCode() {
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
<integer name="productInAtiSelect" title="Products ATI/WT" selection="base.in.ati.select" default="1"/>
|
||||
<integer name="nbDecimalDigitForUnitPrice" title="Nb of digits for unit prices" max="10" default="2"/>
|
||||
<integer name="nbDecimalDigitForSalePrice" title="Nb of digits for sale pruce" max="10" default="2"/>
|
||||
|
||||
<integer name="computeMethodDiscountSelect" title="Compute Method for Discounts" selection="base.compute.method.discount.select" default="1"/>
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.axelor.apps.base.db.repo.ProductRepository;
|
||||
import com.axelor.apps.base.service.CurrencyService;
|
||||
import com.axelor.apps.base.service.PriceListService;
|
||||
import com.axelor.apps.base.service.ProductMultipleQtyService;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
import com.axelor.apps.base.service.app.AppService;
|
||||
import com.axelor.apps.base.service.tax.AccountManagementService;
|
||||
import com.axelor.apps.base.service.tax.FiscalPositionService;
|
||||
import com.axelor.apps.sale.db.PackLine;
|
||||
@@ -438,8 +440,10 @@ public class SaleOrderLineServiceImpl implements SaleOrderLineService {
|
||||
|
||||
BigDecimal price = inAti ? saleOrderLine.getInTaxPrice() : saleOrderLine.getPrice();
|
||||
|
||||
int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForSalePrice();
|
||||
|
||||
return priceListService.computeDiscount(
|
||||
price, saleOrderLine.getDiscountTypeSelect(), saleOrderLine.getDiscountAmount());
|
||||
price, saleOrderLine.getDiscountTypeSelect(), saleOrderLine.getDiscountAmount()).setScale(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.axelor.apps.account.db.TaxLine;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.repo.PriceListLineRepository;
|
||||
import com.axelor.apps.base.db.repo.ProductRepository;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
import com.axelor.apps.base.service.tax.FiscalPositionService;
|
||||
import com.axelor.apps.sale.db.SaleOrder;
|
||||
import com.axelor.apps.sale.db.SaleOrderLine;
|
||||
@@ -390,13 +391,15 @@ public class SaleOrderLineController {
|
||||
Context context = request.getContext();
|
||||
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
|
||||
|
||||
int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForSalePrice();
|
||||
|
||||
BigDecimal qtyUg = saleOrderLine.getProduct().getUg();
|
||||
BigDecimal qty = saleOrderLine.getQty();
|
||||
BigDecimal totalQty = qty.add(qty.multiply(qtyUg).divide(new BigDecimal(100), 4,RoundingMode.HALF_EVEN));
|
||||
Product product = saleOrderLine.getProduct();
|
||||
if(product.getUg() != null && product.getUg().compareTo(BigDecimal.ZERO) > 0){
|
||||
BigDecimal ug = saleOrderLine.getProduct().getUg().divide(new BigDecimal(100), 10, RoundingMode.HALF_EVEN);
|
||||
BigDecimal ugAmount = ug.divide(ug.add(BigDecimal.ONE),10, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100));
|
||||
BigDecimal ug = saleOrderLine.getProduct().getUg().divide(new BigDecimal(100), scale, RoundingMode.HALF_EVEN);
|
||||
BigDecimal ugAmount = ug.divide(ug.add(BigDecimal.ONE),scale, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100));
|
||||
response.setValue("discountTypeSelect", 1);
|
||||
response.setValue("discountAmount", ugAmount);
|
||||
response.setValue("qty", totalQty);
|
||||
|
||||
@@ -164,19 +164,19 @@ public class StockMoveLineServiceImpl implements StockMoveLineService {
|
||||
BigDecimal unitPriceTaxed;
|
||||
if (taxed) {
|
||||
unitPriceTaxed =
|
||||
unitPrice.setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
|
||||
unitPrice.setScale(appBaseService.getNbDecimalDigitForSalePrice(), RoundingMode.HALF_UP);
|
||||
unitPriceUntaxed =
|
||||
unitPrice.divide(
|
||||
taxRate.add(BigDecimal.ONE),
|
||||
appBaseService.getNbDecimalDigitForUnitPrice(),
|
||||
appBaseService.getNbDecimalDigitForSalePrice(),
|
||||
RoundingMode.HALF_UP);
|
||||
} else {
|
||||
unitPriceUntaxed =
|
||||
unitPrice.setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
|
||||
unitPrice.setScale(appBaseService.getNbDecimalDigitForSalePrice(), RoundingMode.HALF_UP);
|
||||
unitPriceTaxed =
|
||||
unitPrice
|
||||
.multiply(taxRate.add(BigDecimal.ONE))
|
||||
.setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
|
||||
.setScale(appBaseService.getNbDecimalDigitForSalePrice(), RoundingMode.HALF_UP);
|
||||
}
|
||||
return this.createStockMoveLine(
|
||||
product,
|
||||
@@ -536,7 +536,7 @@ public class StockMoveLineServiceImpl implements StockMoveLineService {
|
||||
sum = sum.add(newPrice.multiply(newQty));
|
||||
BigDecimal denominator = oldQty.add(newQty);
|
||||
if (denominator.compareTo(BigDecimal.ZERO) != 0) {
|
||||
int scale = appBaseService.getNbDecimalDigitForUnitPrice();
|
||||
int scale = appBaseService.getNbDecimalDigitForSalePrice();
|
||||
newAvgPrice = sum.divide(denominator, scale, RoundingMode.HALF_UP);
|
||||
} else {
|
||||
newAvgPrice = oldAvgPrice;
|
||||
@@ -991,6 +991,7 @@ public class StockMoveLineServiceImpl implements StockMoveLineService {
|
||||
if (stockMove != null && !checkMassesRequired(stockMove, stockMoveLine)) {
|
||||
return product.getNetMass();
|
||||
}
|
||||
|
||||
|
||||
throw new AxelorException(
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
@@ -1201,4 +1202,5 @@ public class StockMoveLineServiceImpl implements StockMoveLineService {
|
||||
stockLocationLineOpt.ifPresent(
|
||||
stockLocationLine -> stockMoveLine.setWapPrice(stockLocationLine.getAvgPrice()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -358,6 +358,7 @@ public class SaleOrderStockServiceImpl implements SaleOrderStockService {
|
||||
@Override
|
||||
public StockMoveLine createStockMoveLine(
|
||||
StockMove stockMove, SaleOrderLine saleOrderLine, BigDecimal qty) throws AxelorException {
|
||||
int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForSalePrice();
|
||||
|
||||
if (this.isStockMoveProduct(saleOrderLine)) {
|
||||
|
||||
@@ -376,7 +377,7 @@ public class SaleOrderStockServiceImpl implements SaleOrderStockService {
|
||||
unit,
|
||||
saleOrderLine.getUnit(),
|
||||
priceDiscounted,
|
||||
5,
|
||||
scale,
|
||||
saleOrderLine.getProduct());
|
||||
requestedReservedQty =
|
||||
unitConversionService.convert(
|
||||
@@ -398,7 +399,7 @@ public class SaleOrderStockServiceImpl implements SaleOrderStockService {
|
||||
.getCompanyExTaxTotal()
|
||||
.divide(
|
||||
saleOrderLine.getQty(),
|
||||
5,
|
||||
scale,
|
||||
RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
stockMove,
|
||||
taxed,
|
||||
taxRate);
|
||||
stockMoveLine.setRequestedReservedQty(requestedReservedQty);
|
||||
stockMoveLine.setRequestedReservedQty(BigDecimal.ZERO);
|
||||
stockMoveLine.setSaleOrderLine(saleOrderLine);
|
||||
stockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
|
||||
TrackingNumberConfiguration trackingNumberConfiguration =
|
||||
@@ -219,14 +219,14 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
fromUnit,
|
||||
toUnit,
|
||||
stockMoveLine.getUnitPriceUntaxed(),
|
||||
appBaseService.getNbDecimalDigitForUnitPrice(),
|
||||
appBaseService.getNbDecimalDigitForSalePrice(),
|
||||
null);
|
||||
BigDecimal unitPriceTaxed =
|
||||
unitConversionService.convert(
|
||||
fromUnit,
|
||||
toUnit,
|
||||
stockMoveLine.getUnitPriceTaxed(),
|
||||
appBaseService.getNbDecimalDigitForUnitPrice(),
|
||||
appBaseService.getNbDecimalDigitForSalePrice(),
|
||||
null);
|
||||
stockMoveLine.setUnitPriceUntaxed(unitPriceUntaxed);
|
||||
stockMoveLine.setUnitPriceTaxed(unitPriceTaxed);
|
||||
|
||||
@@ -183,7 +183,7 @@ public abstract class InvoiceLineGeneratorSupplyChain extends InvoiceLineGenerat
|
||||
this.unit,
|
||||
saleOrPurchaseUnit,
|
||||
this.priceDiscounted,
|
||||
appBaseService.getNbDecimalDigitForUnitPrice(),
|
||||
appBaseService.getNbDecimalDigitForSalePrice(),
|
||||
product);
|
||||
this.unit = saleOrPurchaseUnit;
|
||||
}
|
||||
@@ -276,7 +276,9 @@ public abstract class InvoiceLineGeneratorSupplyChain extends InvoiceLineGenerat
|
||||
|
||||
invoiceLine.setPrice(price);
|
||||
invoiceLine.setInTaxPrice(inTaxPrice);
|
||||
|
||||
// sophal
|
||||
invoiceLine.setTrackingNumber(stockMoveLine.getTrackingNumber());
|
||||
|
||||
analyticMoveLineList =
|
||||
invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
|
||||
analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
|
||||
|
||||
Reference in New Issue
Block a user