IDEMPIERE-5184 Cost Adjustment sets incorrect cost for other schema … (#1175)

* IDEMPIERE-5184 Cost Adjustment sets incorrect cost for other schema when currency blank on header
- also add check to unit test

* IDEMPIERE-5184 Cost Adjustment sets incorrect cost for other schema
- add currency id check to minventory before save
This commit is contained in:
Tony Snook 2022-02-12 14:27:15 +11:00 committed by GitHub
parent a9c4f7b642
commit 0ee5faec8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,10 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-5184 cost adjustment - make currency mandatory
-- Feb 9, 2022, 11:52:39 PM AEDT
UPDATE AD_Field SET IsMandatory='Y', DefaultValue='@$C_Currency_ID@', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2022-02-09 23:52:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204145
;
SELECT Register_Migration_Script ('202202092350_IDEMPIERE-5184.sql') FROM DUAL
;

View File

@ -0,0 +1,7 @@
-- IDEMPIERE-5184 cost adjustment - make currency mandatory
-- Feb 9, 2022, 11:52:39 PM AEDT
UPDATE AD_Field SET IsMandatory='Y', DefaultValue='@$C_Currency_ID@', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2022-02-09 23:52:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204145
;
SELECT Register_Migration_Script ('202202092350_IDEMPIERE-5184.sql') FROM DUAL
;

View File

@ -24,6 +24,7 @@ import java.util.logging.Level;
import org.compiere.model.MAccount;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MClient;
import org.compiere.model.MConversionRate;
import org.compiere.model.MCost;
import org.compiere.model.MCostDetail;
@ -84,7 +85,11 @@ public class Doc_Inventory extends Doc
parentDocSubTypeInv = dt.getDocSubTypeInv();
// IDEMPIERE-3046 Add Currency Field to Cost Adjustment Window
if (!MDocType.DOCSUBTYPEINV_CostAdjustment.equals(parentDocSubTypeInv))
if (MDocType.DOCSUBTYPEINV_CostAdjustment.equals(parentDocSubTypeInv))
{
if (inventory.getC_Currency_ID() == 0)
setC_Currency_ID(MClient.get(getCtx()).getAcctSchema().getC_Currency_ID());
} else
{
setC_Currency_ID (NO_CURRENCY);
}

View File

@ -293,6 +293,14 @@ public class MInventory extends X_M_Inventory implements DocAction
return false;
}
}
String docSubTypeInv = MDocType.get(getC_DocType_ID()).getDocSubTypeInv();
if (MDocType.DOCSUBTYPEINV_CostAdjustment.equals(docSubTypeInv))
{
if (getC_Currency_ID() == 0)
setC_Currency_ID(MClient.get(getCtx()).getAcctSchema().getC_Currency_ID());
}
return true;
} // beforeSave

View File

@ -415,6 +415,17 @@ public class MatchInvTest extends AbstractTestCase {
mulchCost = MCost.getCurrentCost(mulch, 0, getTrxName()).setScale(as.getCostingPrecision(), RoundingMode.HALF_UP);
assertEquals(endProductCost, mulchCost, "Cost not adjusted: " + mulchCost.toPlainString());
//test converted cost for all schemas
MAcctSchema[] schemas = MAcctSchema.getClientAcctSchema(Env.getCtx(), getAD_Client_ID());
for (int i = 0; i < schemas.length; i++) {
BigDecimal expected = MConversionRate.convert (Env.getCtx(),
mulchCost, as.getC_Currency_ID(), schemas[i].getC_Currency_ID(),
inventory.getMovementDate(), 0, getAD_Client_ID(), getAD_Org_ID(), true);
BigDecimal mulchCostConv = MCost.getCurrentCost(mulch, 0, schemas[i], schemas[i].getAD_Org_ID(), MAcctSchema.COSTINGMETHOD_StandardCosting,
BigDecimal.ONE, 0, true, getTrxName()).setScale(schemas[i].getCostingPrecision(), RoundingMode.HALF_UP);
assertEquals(expected, mulchCostConv, "Converted Cost for schema incorrect: " + schemas[i].toString()+ " - " + mulchCostConv.toPlainString());
}
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(bpartner);
order.setIsSOTrx(false);