Skip to content

Commit

Permalink
5522-app - Commission calculation (#5730)
Browse files Browse the repository at this point in the history
5522-app - Commission calculation
  • Loading branch information
metas-ts committed Oct 29, 2019
2 parents 4247bf3 + 42fd45b commit 50cea4b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 20 deletions.
@@ -1,7 +1,7 @@
package de.metas.uom.impl;

import static org.adempiere.model.InterfaceWrapperHelper.load;
import static org.adempiere.model.InterfaceWrapperHelper.loadOutOfTrx;


/*
* #%L
Expand Down Expand Up @@ -61,6 +61,9 @@ public class UOMConversionBL implements IUOMConversionBL
{
private final transient Logger logger = LogManager.getLogger(getClass());

private final IUOMDAO uomDAO = Services.get(IUOMDAO.class);
private final IUOMConversionDAO uomConversionsDAO = Services.get(IUOMConversionDAO.class);

@Override
public BigDecimal convertQty(
@NonNull final UOMConversionContext conversionCtx /* could technically be nullable, right now I don't see why we should allow it */,
Expand All @@ -69,8 +72,8 @@ public BigDecimal convertQty(
@NonNull final UomId uomTo)
{
return convertQty(conversionCtx.getProductId(), qty,
loadOutOfTrx(uomFrom, I_C_UOM.class),
loadOutOfTrx(uomTo, I_C_UOM.class));
uomDAO.getById(uomFrom),
uomDAO.getById(uomTo));
}

@Override
Expand Down Expand Up @@ -104,7 +107,7 @@ public BigDecimal convertQty(@NonNull final UOMConversionContext conversionCtx,
@Override
public Quantity convertQuantityTo(@NonNull final Quantity quantity, final UOMConversionContext conversionCtx, @NonNull final UomId uomToId)
{
final I_C_UOM uomTo = Services.get(IUOMDAO.class).getById(uomToId);
final I_C_UOM uomTo = uomDAO.getById(uomToId);
return convertQuantityTo(quantity, conversionCtx, uomTo);
}

Expand Down Expand Up @@ -132,7 +135,7 @@ public Quantity convertQuantityTo(@NonNull final Quantity quantity, final UOMCon
// Convert current quantity to "uomTo"
final BigDecimal sourceQtyNew = quantity.toBigDecimal();
final int sourceUOMNewId = currentUomId.getRepoId();
final I_C_UOM sourceUOMNew = Services.get(IUOMDAO.class).getById(sourceUOMNewId);
final I_C_UOM sourceUOMNew = uomDAO.getById(sourceUOMNewId);
final BigDecimal qtyNew = convertQty(conversionCtx,
sourceQtyNew,
sourceUOMNew, // From UOM
Expand Down Expand Up @@ -173,9 +176,7 @@ public Quantity computeSum(
@NonNull final Collection<Quantity> quantities,
@NonNull final UomId toUomId)
{
final IUOMDAO uomDao = Services.get(IUOMDAO.class);

final I_C_UOM toUomRecord = uomDao.getById(toUomId);
final I_C_UOM toUomRecord = uomDAO.getById(toUomId);
Quantity resultInTargetUOM = Quantity.zero(toUomRecord);

for (final Quantity currentQuantity : quantities)
Expand Down Expand Up @@ -289,14 +290,12 @@ public BigDecimal convertFromProductUOM(

private UOMConversionsMap getProductConversions(@NonNull final ProductId productId)
{
final IUOMConversionDAO uomConversionsRepo = Services.get(IUOMConversionDAO.class);
return uomConversionsRepo.getProductConversions(productId);
return uomConversionsDAO.getProductConversions(productId);
}

private UOMConversionsMap getGenericRates()
{
final IUOMConversionDAO uomConversionsRepo = Services.get(IUOMConversionDAO.class);
return uomConversionsRepo.getGenericConversions();
return uomConversionsDAO.getGenericConversions();
}

private Optional<UOMConversionRate> getGenericRate(I_C_UOM uomFrom, I_C_UOM uomTo)
Expand Down Expand Up @@ -384,7 +383,7 @@ public BigDecimal convertToProductUOM(
final UOMConversionRate rate = getRateIfExists(productId, fromUomId, toUomId).orElse(null);
if (rate != null)
{
final I_C_UOM toUOM = Services.get(IUOMDAO.class).getById(toUomId);
final I_C_UOM toUOM = uomDAO.getById(toUomId);
final UOMPrecision precision = extractStandardPrecision(toUOM);
return rate.convert(qtyToConvert, precision);
}
Expand Down Expand Up @@ -427,9 +426,8 @@ public Optional<BigDecimal> convert(

private Optional<UOMConversionRate> getTimeConversionRate(@NonNull final UomId fromTimeUomId, @NonNull final UomId toTimeUomId)
{
final IUOMDAO uomsRepo = Services.get(IUOMDAO.class);
final I_C_UOM fromUom = uomsRepo.getById(fromTimeUomId);
final I_C_UOM toUom = uomsRepo.getById(toTimeUomId);
final I_C_UOM fromUom = uomDAO.getById(fromTimeUomId);
final I_C_UOM toUom = uomDAO.getById(toTimeUomId);
return getTimeConversionRate(fromUom, toUom);
}

Expand Down
@@ -0,0 +1,20 @@

-- 2019-10-29T15:45:05.039Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO M_Product_Category (AD_Client_ID,AD_Org_ID,Created,CreatedBy,GuaranteeDaysMin,IsActive,IsDefault,IsPackagingMaterial,IsSelfService,IsSummary,isTradingUnit,MMPolicy,M_Product_Category_ID,Name,PlannedMargin,Updated,UpdatedBy,Value) VALUES (1000000,1000000,TO_TIMESTAMP('2019-10-29 16:45:04','YYYY-MM-DD HH24:MI:SS'),100,0,'Y','N','N','Y','N','N','F',540037,'Provision',0,TO_TIMESTAMP('2019-10-29 16:45:04','YYYY-MM-DD HH24:MI:SS'),100,'Provision')
;

-- 2019-10-29T15:45:05.040Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO M_Product_Category_Trl (AD_Language,M_Product_Category_ID, Description,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.M_Product_Category_ID, t.Description,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, M_Product_Category t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.M_Product_Category_ID=540037 AND NOT EXISTS (SELECT 1 FROM M_Product_Category_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.M_Product_Category_ID=t.M_Product_Category_ID)
;

-- 2019-10-29T15:45:05.055Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO M_Product_Category_Acct (M_Product_Category_ID, C_AcctSchema_ID, AD_Client_ID,AD_Org_ID,IsActive, Created,CreatedBy,Updated,UpdatedBy ,P_Asset_Acct,P_Burden_Acct,P_COGS_Acct,P_CostAdjustment_Acct,P_CostOfProduction_Acct,P_Expense_Acct,P_FloorStock_Acct,P_InventoryClearing_Acct,P_InvoicePriceVariance_Acct,P_Labor_Acct,P_MethodChangeVariance_Acct,P_MixVariance_Acct,P_OutsideProcessing_Acct,P_Overhead_Acct,P_PurchasePriceVariance_Acct,P_RateVariance_Acct,P_Revenue_Acct,P_Scrap_Acct,P_TradeDiscountGrant_Acct,P_TradeDiscountRec_Acct,P_UsageVariance_Acct,P_WIP_Acct) SELECT 540037, p.C_AcctSchema_ID, p.AD_Client_ID,0,'Y', now(),100,now(),100,p.P_Asset_Acct,p.P_Burden_Acct,p.P_COGS_Acct,p.P_CostAdjustment_Acct,p.P_CostOfProduction_Acct,p.P_Expense_Acct,p.P_FloorStock_Acct,p.P_InventoryClearing_Acct,p.P_InvoicePriceVariance_Acct,p.P_Labor_Acct,p.P_MethodChangeVariance_Acct,p.P_MixVariance_Acct,p.P_OutsideProcessing_Acct,p.P_Overhead_Acct,p.P_PurchasePriceVariance_Acct,p.P_RateVariance_Acct,p.P_Revenue_Acct,p.P_Scrap_Acct,p.P_TradeDiscountGrant_Acct,p.P_TradeDiscountRec_Acct,p.P_UsageVariance_Acct,p.P_WIP_Acct FROM C_AcctSchema_Default p WHERE p.AD_Client_ID=1000000 AND NOT EXISTS (SELECT 1 FROM M_Product_Category_Acct e WHERE e.C_AcctSchema_ID=p.C_AcctSchema_ID AND e.M_Product_Category_ID=540037)
;

-- 2019-10-29T15:45:05.090Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_TreeNode (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, AD_Tree_ID, Node_ID, Parent_ID, SeqNo) SELECT t.AD_Client_ID,0, 'Y', now(), 100, now(), 100,t.AD_Tree_ID, 540037, 0, 999 FROM AD_Tree t WHERE t.AD_Client_ID=1000000 AND t.IsActive='Y' AND t.IsAllNodes='Y' AND t.AD_Table_ID=209 AND NOT EXISTS (SELECT * FROM AD_TreeNode e WHERE e.AD_Tree_ID=t.AD_Tree_ID AND Node_ID=540037)
;
@@ -1,8 +1,10 @@

-- 2019-09-19T19:03:33.502Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO M_Product (AD_Client_ID,AD_Org_ID,Created,CreatedBy,C_UOM_ID,Discontinued,Fresh_CropPlanning,Fresh_WashSampleRequired,GuaranteeDaysMin,IsActive,IsBOM,IsCategoryProduct,IsColdChain,IsDiverse,IsDropShip,IsExcludeAutoDelivery,IsInvoicePrintDetails,IsNarcotic,IsPharmaProduct,IsPickListPrintDetails,IsPrescription,IsPurchased,IsQuotationGroupping,IsSelfService,IsSold,IsStocked,IsSummary,IsTFG,IsVerified,IsWebStoreFeatured,LowLevel,M_Product_Category_ID,M_Product_ID,Name,Processing,ProductType,SalesRep_ID,ShelfDepth,ShelfHeight,ShelfWidth,UnitsPerPack,UnitsPerPallet,Updated,UpdatedBy,Value,Volume,Weight) VALUES
(1000000,0,TO_TIMESTAMP('2019-09-19 21:03:33','YYYY-MM-DD HH24:MI:SS'),100,100,'N','N','N',0,'Y','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','N',0,2001603,540420,'Provision','N','S',100,0,0,0,0,0,TO_TIMESTAMP('2019-09-19 21:03:33','YYYY-MM-DD HH24:MI:SS'),100,'COMMISSION',0,0)
INSERT INTO M_Product (AD_Client_ID,AD_Org_ID,Created,CreatedBy,C_UOM_ID,Discontinued,Fresh_CropPlanning,Fresh_WashSampleRequired,GuaranteeDaysMin,IsActive,IsBOM,IsCategoryProduct,IsColdChain,IsDiverse,IsDropShip,IsExcludeAutoDelivery,IsInvoicePrintDetails,IsNarcotic,IsPharmaProduct,IsPickListPrintDetails,IsPrescription,IsPurchased,IsQuotationGroupping,IsSelfService,IsSold,IsStocked,IsSummary,IsTFG,IsVerified,IsWebStoreFeatured,
LowLevel,M_Product_Category_ID,M_Product_ID,Name,Processing,ProductType,SalesRep_ID,ShelfDepth,ShelfHeight,ShelfWidth,UnitsPerPack,UnitsPerPallet,Updated,UpdatedBy,Value,Volume,Weight) VALUES
(1000000,0,TO_TIMESTAMP('2019-09-19 21:03:33','YYYY-MM-DD HH24:MI:SS'),100,100,'N','N','N',0,'Y','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','N',
0,540037,540420,'Provision','N','S',100,0,0,0,0,0,TO_TIMESTAMP('2019-09-19 21:03:33','YYYY-MM-DD HH24:MI:SS'),100,'COMMISSION',0,0)
;

-- 2019-09-19T19:03:33.507Z
Expand Down
@@ -0,0 +1,35 @@
-- 2019-10-29T15:43:57.221Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO C_UOM (AD_Client_ID,AD_Org_ID,CostingPrecision,Created,CreatedBy,C_UOM_ID,Description,IsActive,IsDefault,Name,StdPrecision,UOMSymbol,Updated,UpdatedBy,X12DE355) VALUES (1000000,0,0,TO_TIMESTAMP('2019-10-29 16:43:57','YYYY-MM-DD HH24:MI:SS'),100,540049,'Die Standardgenauigkeit bestimmt die Anzahl der Nachkommastellen auf der Provisionsabrechnung.','Y','N','Provisionspunkt',2,'Pkt',TO_TIMESTAMP('2019-10-29 16:43:57','YYYY-MM-DD HH24:MI:SS'),100,'PTS')
;

-- 2019-10-29T15:43:57.223Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO C_UOM_Trl (AD_Language,C_UOM_ID, Description,Name,UOMSymbol, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language, t.C_UOM_ID, t.Description,t.Name,t.UOMSymbol, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, C_UOM t WHERE l.IsActive='Y'AND (l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N') AND t.C_UOM_ID=540049 AND NOT EXISTS (SELECT 1 FROM C_UOM_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.C_UOM_ID=t.C_UOM_ID)
;

-- 2019-10-29T15:44:00.917Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE C_UOM_Trl SET IsTranslated='Y',Updated=TO_TIMESTAMP('2019-10-29 16:44:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Language='de_CH' AND C_UOM_ID=540049
;

-- 2019-10-29T15:44:08.400Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE C_UOM_Trl SET Description='', Name='Commission point',Updated=TO_TIMESTAMP('2019-10-29 16:44:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Language='en_US' AND C_UOM_ID=540049
;

-- 2019-10-29T15:44:23.414Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE M_Product SET C_UOM_ID=540049, IsStocked='N',Updated=TO_TIMESTAMP('2019-10-29 16:44:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE M_Product_ID=540420
;

-- 2019-10-29T15:45:16.310Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE M_Product SET IsStocked='N', M_Product_Category_ID=540037,Updated=TO_TIMESTAMP('2019-10-29 16:45:16','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE M_Product_ID=540420
;

-- 2019-10-29T15:48:22.952Z
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
UPDATE M_ProductPrice SET C_UOM_ID=540049,Updated=TO_TIMESTAMP('2019-10-29 16:48:22','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE M_ProductPrice_ID=2767028
;

Expand Up @@ -141,9 +141,8 @@ public abstract class AbstractInvoiceBL implements IInvoiceBL
public static final String SYSCONFIG_C_Invoice_PaymentRule = "de.metas.invoice.C_Invoice_PaymentRule";

@Override
public final I_C_Invoice creditInvoice(final I_C_Invoice invoice, final IInvoiceCreditContext creditCtx)
public final I_C_Invoice creditInvoice(@NonNull final I_C_Invoice invoice, final IInvoiceCreditContext creditCtx)
{
Check.assumeNotNull(invoice, "Param 'invoice' is not null");
Check.errorIf(isCreditMemo(invoice), "Param 'invoice'={} may not be a credit memo");
Check.errorIf(invoice.isPaid(), "Param 'invoice'={} may not yet be paid");

Expand Down

0 comments on commit 50cea4b

Please sign in to comment.