From f39dfd1dc3a4e19caa3b90aee8fbcde7d45daf17 Mon Sep 17 00:00:00 2001 From: Deepak Pansheriya Date: Wed, 3 Jan 2024 15:37:53 +0530 Subject: [PATCH] IDEMPIERE-5602: removing priceEntered and added LineNetAmt on Expense report line. (#2138) Co-authored-by: Carlos Ruiz --- .../oracle/202312041613_IDEMPIERE-5602.sql | 51 +++++++++++++++++ .../202312041613_IDEMPIERE-5602.sql | 48 ++++++++++++++++ .../compiere/model/CalloutTimeExpense.java | 55 +++---------------- .../org/compiere/process/ExpenseSOrder.java | 15 +---- .../compiere/model/I_S_TimeExpenseLine.java | 16 +++--- .../org/compiere/model/MTimeExpenseLine.java | 28 ++++------ .../compiere/model/X_S_TimeExpenseLine.java | 21 +++---- 7 files changed, 139 insertions(+), 95 deletions(-) create mode 100644 migration/iD10/oracle/202312041613_IDEMPIERE-5602.sql create mode 100644 migration/iD10/postgresql/202312041613_IDEMPIERE-5602.sql diff --git a/migration/iD10/oracle/202312041613_IDEMPIERE-5602.sql b/migration/iD10/oracle/202312041613_IDEMPIERE-5602.sql new file mode 100644 index 0000000000..67658ab864 --- /dev/null +++ b/migration/iD10/oracle/202312041613_IDEMPIERE-5602.sql @@ -0,0 +1,51 @@ +-- Added Line Amount field in Expense Report Line and removed Price field from Expense Report Line +SELECT register_migration_script('202312041613_IDEMPIERE-5602.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +--Update Expense Amt +UPDATE S_TimeExpenseLine SET ExpenseAmt = PriceEntered WHERE PriceEntered > 0 AND IsTimeReport = 'N'; + +--Update Converted Amt +UPDATE S_TimeExpenseLine SET ConvertedAmt = currencyconvert(ExpenseAmt,C_Currency_ID,(SELECT pl.C_Currency_ID FROM S_TimeExpense te INNER JOIN M_PriceList pl ON pl.M_PriceList_ID=te.M_PriceList_ID WHERE te.S_TimeExpense_ID=S_TimeExpenseLine.S_TimeExpense_ID),DateExpense,0,AD_Client_ID,AD_Org_ID) WHERE ExpenseAmt > 0 AND IsTimeReport = 'N'; + +-- Dec 4, 2023, 4:16:29 PM IST +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (216303,0,'Line Amount','Line Extended Amount (Quantity * Actual Price) without Freight and Charges','Indicates the extended line amount based on the quantity and the actual price. Any additional charges or freight are not included. The Amount may or may not include tax. If the price list is inclusive tax, the line amount is the same as the line total.',488,'LineNetAmt',22,'N','N','N','N','N',0,'N',12,0,0,'Y',TO_TIMESTAMP('2023-12-04 16:16:28','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 16:16:28','YYYY-MM-DD HH24:MI:SS'),100,441,'Y','N','D','N','N','N','Y','e3f82050-95c4-4c53-8e3b-8e9344000ea2','Y',0,'N','N','N') +; + +-- Dec 4, 2023, 4:16:47 PM IST +ALTER TABLE S_TimeExpenseLine ADD LineNetAmt NUMBER DEFAULT NULL +; + +-- Dec 4, 2023, 4:20:04 PM IST +INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,DisplayLogic,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (208092,'Line Amount','Line Extended Amount (Quantity * Actual Price) without Freight and Charges','Indicates the extended line amount based on the quantity and the actual price. Any additional charges or freight are not included. The Amount may or may not include tax. If the price list is inclusive tax, the line amount is the same as the line total.',413,216303,'Y',22,155,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-12-04 16:20:04','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 16:20:04','YYYY-MM-DD HH24:MI:SS'),100,'Y','Y','@IsTimeReport@=N | @IsInvoiced@=Y','D','fd80a0f0-b3ab-49c4-8020-867a858d6b0f','Y',155,2) +; + +-- Dec 4, 2023, 4:25:01 PM IST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutTimeExpense.amount',Updated=TO_DATE('2023-12-04 16:25:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=6875 +; + +-- Dec 4, 2023, 4:30:07 PM IST +UPDATE AD_Field SET XPosition=1,Updated=TO_DATE('2023-12-04 16:30:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5463 +; + +-- Dec 4, 2023, 4:30:07 PM IST +UPDATE AD_Field SET IsReadOnly='N',Updated=TO_DATE('2023-12-04 16:30:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5462 +; + +-- 04-Dec-2023, 4:49:15 PM IST +DELETE FROM AD_Field WHERE AD_Field_ID=207572 +; + +-- 04-Dec-2023, 4:49:32 PM IST +DELETE FROM AD_Column WHERE AD_Column_ID=215777 +; + +-- 04-Dec-2023, 4:49:32 PM IST +ALTER TABLE S_TimeExpenseLine DROP COLUMN PriceEntered +; + +--Set Line Amount +UPDATE S_TimeExpenseLine SET LineNetAmt = ExpenseAmt * Qty WHERE ExpenseAmt > 0 AND IsTimeReport = 'N'; + diff --git a/migration/iD10/postgresql/202312041613_IDEMPIERE-5602.sql b/migration/iD10/postgresql/202312041613_IDEMPIERE-5602.sql new file mode 100644 index 0000000000..0995531429 --- /dev/null +++ b/migration/iD10/postgresql/202312041613_IDEMPIERE-5602.sql @@ -0,0 +1,48 @@ +-- Added Line Amount field in Expense Report Line and removed Price field from Expense Report Line +SELECT register_migration_script('202312041613_IDEMPIERE-5602.sql') FROM dual; + +--Update Expense Amt +UPDATE S_TimeExpenseLine SET ExpenseAmt = PriceEntered WHERE PriceEntered > 0 AND IsTimeReport = 'N'; + +--Update Converted Amt +UPDATE S_TimeExpenseLine SET ConvertedAmt = currencyconvert(ExpenseAmt,C_Currency_ID,(SELECT pl.C_Currency_ID FROM S_TimeExpense te INNER JOIN M_PriceList pl ON pl.M_PriceList_ID=te.M_PriceList_ID WHERE te.S_TimeExpense_ID=S_TimeExpenseLine.S_TimeExpense_ID),DateExpense,0,AD_Client_ID,AD_Org_ID) WHERE ExpenseAmt > 0 AND IsTimeReport = 'N'; + +-- Dec 4, 2023, 4:16:29 PM IST +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (216303,0,'Line Amount','Line Extended Amount (Quantity * Actual Price) without Freight and Charges','Indicates the extended line amount based on the quantity and the actual price. Any additional charges or freight are not included. The Amount may or may not include tax. If the price list is inclusive tax, the line amount is the same as the line total.',488,'LineNetAmt',22,'N','N','N','N','N',0,'N',12,0,0,'Y',TO_TIMESTAMP('2023-12-04 16:16:28','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 16:16:28','YYYY-MM-DD HH24:MI:SS'),100,441,'Y','N','D','N','N','N','Y','e3f82050-95c4-4c53-8e3b-8e9344000ea2','Y',0,'N','N','N') +; + +-- Dec 4, 2023, 4:16:47 PM IST +ALTER TABLE S_TimeExpenseLine ADD COLUMN LineNetAmt NUMERIC DEFAULT NULL +; + +-- Dec 4, 2023, 4:20:04 PM IST +INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,DisplayLogic,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (208092,'Line Amount','Line Extended Amount (Quantity * Actual Price) without Freight and Charges','Indicates the extended line amount based on the quantity and the actual price. Any additional charges or freight are not included. The Amount may or may not include tax. If the price list is inclusive tax, the line amount is the same as the line total.',413,216303,'Y',22,155,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-12-04 16:20:04','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 16:20:04','YYYY-MM-DD HH24:MI:SS'),100,'Y','Y','@IsTimeReport@=N | @IsInvoiced@=Y','D','fd80a0f0-b3ab-49c4-8020-867a858d6b0f','Y',155,2) +; + +-- Dec 4, 2023, 4:25:01 PM IST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutTimeExpense.amount',Updated=TO_TIMESTAMP('2023-12-04 16:25:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=6875 +; + +-- Dec 4, 2023, 4:30:07 PM IST +UPDATE AD_Field SET XPosition=1,Updated=TO_TIMESTAMP('2023-12-04 16:30:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5463 +; + +-- Dec 4, 2023, 4:30:07 PM IST +UPDATE AD_Field SET IsReadOnly='N',Updated=TO_DATE('2023-12-04 16:30:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5462 +; + +-- 04-Dec-2023, 4:49:15 PM IST +DELETE FROM AD_Field WHERE AD_Field_ID=207572 +; + +-- 04-Dec-2023, 4:49:32 PM IST +DELETE FROM AD_Column WHERE AD_Column_ID=215777 +; + +-- 04-Dec-2023, 4:49:32 PM IST +ALTER TABLE S_TimeExpenseLine DROP COLUMN PriceEntered +; + +--Set Line Amount +UPDATE S_TimeExpenseLine SET LineNetAmt = ExpenseAmt * Qty WHERE ExpenseAmt > 0 AND IsTimeReport = 'N'; + diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java index a8e7893f87..21d1211790 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java @@ -39,7 +39,7 @@ public class CalloutTimeExpense extends CalloutEngine /** * Expense Report Line * - called from M_Product_ID, S_ResourceAssignment_ID - * - set Price + * - set ExpenseAmt * @param ctx context * @param WindowNo current Window No * @param mTab Grid Tab @@ -165,14 +165,14 @@ public class CalloutTimeExpense extends CalloutEngine // finish if (priceActual == null) priceActual = Env.ZERO; - mTab.setValue("PriceEntered", priceActual); + mTab.setValue("ExpenseAmt", priceActual); return ""; } // Expense_Product /** * Expense - Amount. * - called from ExpenseAmt, C_Currency_ID - * - calculates ConvertedAmt + * - calculates ConvertedAmt and Line Net Amount * @param ctx context * @param WindowNo current Window No * @param mTab Grid Tab @@ -204,53 +204,14 @@ public class CalloutTimeExpense extends CalloutEngine DateExpense, 0, AD_Client_ID, AD_Org_ID); } mTab.setValue("ConvertedAmt", ConvertedAmt); + + BigDecimal qty = (BigDecimal)mTab.getValue(MTimeExpenseLine.COLUMNNAME_Qty); + BigDecimal lineNetAmt = ExpenseAmt.multiply(qty); + mTab.setValue(MTimeExpenseLine.COLUMNNAME_LineNetAmt, lineNetAmt); + if (log.isLoggable(Level.FINE)) log.fine("= ConvertedAmt=" + ConvertedAmt); return ""; } // Expense_Amount - - /** - * Price or Quantity. - * - called from Price, Quantity - * - calculates Expense Amount - * @param ctx context - * @param WindowNo current Window No - * @param mTab Grid Tab - * @param mField Grid Field - * @param value New Value - * @return null or error message - */ - public String priceOrQty(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - BigDecimal qty = Env.ZERO; - BigDecimal price = Env.ZERO; - - String columnName = mField.getColumnName(); - if (MTimeExpenseLine.COLUMNNAME_Qty.equals(columnName)) - { - qty = (BigDecimal) value; - price = (BigDecimal) mTab.getValue(MTimeExpenseLine.COLUMNNAME_PriceEntered); - } - else - { - price = (BigDecimal) value; - qty = (BigDecimal) mTab.getValue(MTimeExpenseLine.COLUMNNAME_Qty); - } - - if(qty == null) - { - qty = Env.ZERO; - } - - if(price == null) - { - price = Env.ZERO; - } - - BigDecimal expenseAmt = price.multiply(qty); - mTab.setValue(MTimeExpenseLine.COLUMNNAME_ExpenseAmt, expenseAmt); - - return ""; - } // Price or Quantity } // CalloutTimeExpense diff --git a/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java b/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java index 6453c85563..3d229129a4 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java +++ b/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java @@ -16,14 +16,12 @@ *****************************************************************************/ package org.compiere.process; -import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; import java.util.logging.Level; import org.compiere.model.MBPartner; -import org.compiere.model.MConversionRate; import org.compiere.model.MOrder; import org.compiere.model.MOrderLine; import org.compiere.model.MProcessPara; @@ -31,7 +29,6 @@ import org.compiere.model.MProject; import org.compiere.model.MTimeExpense; import org.compiere.model.MTimeExpenseLine; import org.compiere.util.DB; -import org.compiere.util.Env; /** * Create Sales Orders from Expense Reports @@ -238,17 +235,7 @@ public class ExpenseSOrder extends SvrProcess ol.setC_Activity_ID(tel.getC_Activity_ID()); ol.setC_Campaign_ID(tel.getC_Campaign_ID()); // - BigDecimal price = tel.getPriceInvoiced(); // - if (price != null && price.compareTo(Env.ZERO) != 0) - { - if (tel.getC_Currency_ID() != m_order.getC_Currency_ID()) - price = MConversionRate.convert(getCtx(), price, - tel.getC_Currency_ID(), m_order.getC_Currency_ID(), - m_order.getAD_Client_ID(), m_order.getAD_Org_ID()); - ol.setPrice(price); - } - else - ol.setPrice(); + ol.setPrice(tel.getPriceReimbursed()); // if (tel.getC_UOM_ID() != 0 && ol.getC_UOM_ID() == 0) ol.setC_UOM_ID(tel.getC_UOM_ID()); ol.setTax(); diff --git a/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java index a7c170f5ab..e1e7dfeadb 100644 --- a/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java @@ -373,18 +373,18 @@ public interface I_S_TimeExpenseLine */ public String getNote(); - /** Column name PriceEntered */ - public static final String COLUMNNAME_PriceEntered = "PriceEntered"; + /** Column name LineNetAmt */ + public static final String COLUMNNAME_LineNetAmt = "LineNetAmt"; - /** Set Price. - * Price Entered - the price based on the selected/base UoM + /** Set Line Amount. + * Line Extended Amount (Quantity * Actual Price) without Freight and Charges */ - public void setPriceEntered (BigDecimal PriceEntered); + public void setLineNetAmt (BigDecimal LineNetAmt); - /** Get Price. - * Price Entered - the price based on the selected/base UoM + /** Get Line Amount. + * Line Extended Amount (Quantity * Actual Price) without Freight and Charges */ - public BigDecimal getPriceEntered(); + public BigDecimal getLineNetAmt(); /** Column name PriceInvoiced */ public static final String COLUMNNAME_PriceInvoiced = "PriceInvoiced"; diff --git a/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java index 08d4d9c21f..badfa25737 100644 --- a/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java @@ -37,7 +37,7 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine /** * */ - private static final long serialVersionUID = -815975460880303779L; + private static final long serialVersionUID = 3580618153284679385L; /** * UUID based Constructor @@ -170,7 +170,7 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine */ public BigDecimal getApprovalAmt() { - return getConvertedAmt(); + return getQty().multiply(getConvertedAmt()); } // getApprovalAmt @@ -211,19 +211,6 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine return false; } - //calculate expense amount - if(newRecord || is_ValueChanged(COLUMNNAME_Qty) || is_ValueChanged(COLUMNNAME_PriceEntered)) - { - BigDecimal price = getPriceEntered(); - if(price == null) - { - price = Env.ZERO; - } - - BigDecimal expenseAmt = price.multiply(getQty()); - setExpenseAmt(expenseAmt); - } - // Calculate Converted Amount if (newRecord || is_ValueChanged("ExpenseAmt") || is_ValueChanged("C_Currency_ID")) { @@ -236,10 +223,19 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine getDateExpense(), 0, getAD_Client_ID(), getAD_Org_ID()) ); } } + + // calculate Line Net Amount + if (newRecord || is_ValueChanged(COLUMNNAME_Qty) || is_ValueChanged(COLUMNNAME_ExpenseAmt)) + { + BigDecimal lineNetAmt = getExpenseAmt().multiply(getQty()); + setLineNetAmt(lineNetAmt); + } + if (isTimeReport()) { setExpenseAmt(Env.ZERO); setConvertedAmt(Env.ZERO); + setLineNetAmt(Env.ZERO); } return true; } // beforeSave @@ -329,7 +325,7 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine { String sql = "UPDATE S_TimeExpense te" + " SET ApprovalAmt = " - + "(SELECT SUM(ConvertedAmt) FROM S_TimeExpenseLine tel " + + "(SELECT SUM(Qty*ConvertedAmt) FROM S_TimeExpenseLine tel " + "WHERE te.S_TimeExpense_ID=tel.S_TimeExpense_ID) " + "WHERE S_TimeExpense_ID=" + getS_TimeExpense_ID(); @SuppressWarnings("unused") diff --git a/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java index 96553da0db..e283491065 100644 --- a/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java @@ -34,7 +34,7 @@ public class X_S_TimeExpenseLine extends PO implements I_S_TimeExpenseLine, I_Pe /** * */ - private static final long serialVersionUID = 20231222L; + private static final long serialVersionUID = 20240102L; /** Standard Constructor */ public X_S_TimeExpenseLine (Properties ctx, int S_TimeExpenseLine_ID, String trxName) @@ -622,22 +622,23 @@ public class X_S_TimeExpenseLine extends PO implements I_S_TimeExpenseLine, I_Pe return (String)get_Value(COLUMNNAME_Note); } - /** Set Price. - @param PriceEntered Price Entered - the price based on the selected/base UoM + /** Set Line Amount. + @param LineNetAmt + Line Extended Amount (Quantity * Actual Price) without Freight and Charges */ - public void setPriceEntered (BigDecimal PriceEntered) + public void setLineNetAmt (BigDecimal LineNetAmt) { - set_Value (COLUMNNAME_PriceEntered, PriceEntered); + set_Value (COLUMNNAME_LineNetAmt, LineNetAmt); } - /** Get Price. - @return Price Entered - the price based on the selected/base UoM + /** Get Line Amount. + @return Line Extended Amount (Quantity * Actual Price) without Freight and Charges */ - public BigDecimal getPriceEntered() + public BigDecimal getLineNetAmt () { - BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_PriceEntered); + BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_LineNetAmt); if (bd == null) - return Env.ZERO; + return Env.ZERO; return bd; }