IDEMPIERE-2057 1003719 Modify "Update Costing" process to create a cost adjustment document.

This commit is contained in:
Heng Sin Low 2014-07-02 10:23:54 +08:00
parent 1be17505b8
commit a1685042c5
5 changed files with 200 additions and 24 deletions

View File

@ -0,0 +1,43 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Jul 1, 2014 3:44:10 PM MYT
-- 1003719 Modify "Update Costing" process to create a cost adjustment document
UPDATE AD_Process_Para SET SeqNo=120,Updated=TO_DATE('2014-07-01 15:44:10','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=53378
;
-- Jul 1, 2014 3:46:18 PM MYT
INSERT INTO AD_Process_Para (AD_Process_Para_ID,IsRange,AD_Process_Para_UU,AD_Process_ID,AD_Reference_ID,AD_Val_Rule_ID,IsMandatory,DisplayLogic,EntityType,Name,ColumnName,FieldLength,IsCentrallyMaintained,SeqNo,IsActive,UpdatedBy,Updated,CreatedBy,AD_Org_ID,IsEncrypted,AD_Client_ID,Created) VALUES (200102,'N','8e8036a8-ae8d-4470-a607-9cd048741419',219,19,200050,'N','@IsUpdateCosting@=''Y''','D','Cost Adjustment Document Type','C_DocType_ID',10,'N',110,'Y',100,TO_DATE('2014-07-01 15:46:18','YYYY-MM-DD HH24:MI:SS'),100,0,'N',0,TO_DATE('2014-07-01 15:46:18','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:51:17 PM MYT
INSERT INTO AD_Element (ColumnName,AD_Element_ID,Help,Name,Description,PrintName,AD_Element_UU,Updated,AD_Org_ID,CreatedBy,UpdatedBy,IsActive,AD_Client_ID,EntityType,Created) VALUES ('M_CostingLine_ID',202750,'The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Cost Adjustment Line','Unique line in an Inventory cost adjustment document','Cost Adjustment Line','e60cd491-bd9f-4f5f-b031-7401461264c1',TO_DATE('2014-07-01 15:51:16','YYYY-MM-DD HH24:MI:SS'),0,100,100,'Y',0,'D',TO_DATE('2014-07-01 15:51:16','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:53:05 PM MYT
INSERT INTO AD_Column (SeqNoSelection,IsSyncDatabase,Version,AD_Column_ID,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsParent,FieldLength,IsSelectionColumn,IsKey,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsUpdateable,ColumnName,Description,Help,Name,IsAllowCopy,CreatedBy,Updated,IsActive,UpdatedBy,IsToolbarButton,IsAlwaysUpdateable,AD_Client_ID,EntityType,IsEncrypted,IsSecure,FKConstraintType,AD_Element_ID,AD_Reference_ID,AD_Reference_Value_ID,AD_Table_ID,AD_Org_ID,Created) VALUES (0,'N',0,211562,'N','N','N',0,'N',10,'N','N','N','Y','044a1793-a72b-49a0-aa64-f1b99565a884','Y','M_CostingLine_ID','Unique line in an Inventory cost adjustment document','The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Cost Adjustment Line','N',100,TO_DATE('2014-07-01 15:53:04','YYYY-MM-DD HH24:MI:SS'),'Y',100,'N','N',0,'D','N','N','N',202750,30,296,572,0,TO_DATE('2014-07-01 15:53:04','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:53:13 PM MYT
UPDATE AD_Column SET FKConstraintType='N', FKConstraintName='MCostingLine_IInventory',Updated=TO_DATE('2014-07-01 15:53:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211562
;
-- Jul 1, 2014 3:53:13 PM MYT
ALTER TABLE I_Inventory ADD M_CostingLine_ID NUMBER(10) DEFAULT NULL
;
-- Jul 1, 2014 3:53:15 PM MYT
ALTER TABLE I_Inventory ADD CONSTRAINT MCostingLine_IInventory FOREIGN KEY (M_CostingLine_ID) REFERENCES m_inventoryline(m_inventoryline_id) DEFERRABLE INITIALLY DEFERRED
;
-- Jul 1, 2014 3:54:41 PM MYT
UPDATE AD_Field SET SeqNo=300, SeqNoGrid=300,Updated=TO_DATE('2014-07-01 15:54:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=6697
;
-- Jul 1, 2014 3:56:40 PM MYT
INSERT INTO AD_Field (SortNo,IsEncrypted,DisplayLength,IsSameLine,IsHeading,SeqNo,IsCentrallyMaintained,AD_Field_ID,IsReadOnly,Help,Description,Name,AD_Field_UU,IsDisplayed,IsFieldOnly,UpdatedBy,AD_Org_ID,CreatedBy,Updated,IsActive,IsDisplayedGrid,SeqNoGrid,XPosition,IsQuickEntry,AD_Client_ID,ColumnSpan,NumLines,IsAdvancedField,IsDefaultFocus,AD_Column_ID,AD_Tab_ID,EntityType,Created) VALUES (0,'N',0,'N','N',290,'Y',203261,'N','The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Unique line in an Inventory cost adjustment document','Cost Adjustment Line','c8667068-b4f9-43dd-a80d-2b910584a565','Y','N',100,0,100,TO_DATE('2014-07-01 15:56:39','YYYY-MM-DD HH24:MI:SS'),'Y','Y',290,1,'N',0,2,1,'N','N',211562,481,'D',TO_DATE('2014-07-01 15:56:39','YYYY-MM-DD HH24:MI:SS'))
;
SELECT register_migration_script('201407021018_1003719.sql') FROM dual
;

View File

@ -0,0 +1,40 @@
-- Jul 1, 2014 3:44:10 PM MYT
-- 1003719 Modify "Update Costing" process to create a cost adjustment document
UPDATE AD_Process_Para SET SeqNo=120,Updated=TO_TIMESTAMP('2014-07-01 15:44:10','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=53378
;
-- Jul 1, 2014 3:46:18 PM MYT
INSERT INTO AD_Process_Para (AD_Process_Para_ID,IsRange,AD_Process_Para_UU,AD_Process_ID,AD_Reference_ID,AD_Val_Rule_ID,IsMandatory,DisplayLogic,EntityType,Name,ColumnName,FieldLength,IsCentrallyMaintained,SeqNo,IsActive,UpdatedBy,Updated,CreatedBy,AD_Org_ID,IsEncrypted,AD_Client_ID,Created) VALUES (200102,'N','8e8036a8-ae8d-4470-a607-9cd048741419',219,19,200050,'N','@IsUpdateCosting@=''Y''','D','Cost Adjustment Document Type','C_DocType_ID',10,'N',110,'Y',100,TO_TIMESTAMP('2014-07-01 15:46:18','YYYY-MM-DD HH24:MI:SS'),100,0,'N',0,TO_TIMESTAMP('2014-07-01 15:46:18','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:51:17 PM MYT
INSERT INTO AD_Element (ColumnName,AD_Element_ID,Help,Name,Description,PrintName,AD_Element_UU,Updated,AD_Org_ID,CreatedBy,UpdatedBy,IsActive,AD_Client_ID,EntityType,Created) VALUES ('M_CostingLine_ID',202750,'The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Cost Adjustment Line','Unique line in an Inventory cost adjustment document','Cost Adjustment Line','e60cd491-bd9f-4f5f-b031-7401461264c1',TO_TIMESTAMP('2014-07-01 15:51:16','YYYY-MM-DD HH24:MI:SS'),0,100,100,'Y',0,'D',TO_TIMESTAMP('2014-07-01 15:51:16','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:53:05 PM MYT
INSERT INTO AD_Column (SeqNoSelection,IsSyncDatabase,Version,AD_Column_ID,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsParent,FieldLength,IsSelectionColumn,IsKey,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsUpdateable,ColumnName,Description,Help,Name,IsAllowCopy,CreatedBy,Updated,IsActive,UpdatedBy,IsToolbarButton,IsAlwaysUpdateable,AD_Client_ID,EntityType,IsEncrypted,IsSecure,FKConstraintType,AD_Element_ID,AD_Reference_ID,AD_Reference_Value_ID,AD_Table_ID,AD_Org_ID,Created) VALUES (0,'N',0,211562,'N','N','N',0,'N',10,'N','N','N','Y','044a1793-a72b-49a0-aa64-f1b99565a884','Y','M_CostingLine_ID','Unique line in an Inventory cost adjustment document','The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Cost Adjustment Line','N',100,TO_TIMESTAMP('2014-07-01 15:53:04','YYYY-MM-DD HH24:MI:SS'),'Y',100,'N','N',0,'D','N','N','N',202750,30,296,572,0,TO_TIMESTAMP('2014-07-01 15:53:04','YYYY-MM-DD HH24:MI:SS'))
;
-- Jul 1, 2014 3:53:13 PM MYT
UPDATE AD_Column SET FKConstraintType='N', FKConstraintName='MCostingLine_IInventory',Updated=TO_TIMESTAMP('2014-07-01 15:53:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211562
;
-- Jul 1, 2014 3:53:13 PM MYT
ALTER TABLE I_Inventory ADD COLUMN M_CostingLine_ID NUMERIC(10) DEFAULT NULL
;
-- Jul 1, 2014 3:53:15 PM MYT
ALTER TABLE I_Inventory ADD CONSTRAINT MCostingLine_IInventory FOREIGN KEY (M_CostingLine_ID) REFERENCES m_inventoryline(m_inventoryline_id) DEFERRABLE INITIALLY DEFERRED
;
-- Jul 1, 2014 3:54:41 PM MYT
UPDATE AD_Field SET SeqNo=300, SeqNoGrid=300,Updated=TO_TIMESTAMP('2014-07-01 15:54:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=6697
;
-- Jul 1, 2014 3:56:40 PM MYT
INSERT INTO AD_Field (SortNo,IsEncrypted,DisplayLength,IsSameLine,IsHeading,SeqNo,IsCentrallyMaintained,AD_Field_ID,IsReadOnly,Help,Description,Name,AD_Field_UU,IsDisplayed,IsFieldOnly,UpdatedBy,AD_Org_ID,CreatedBy,Updated,IsActive,IsDisplayedGrid,SeqNoGrid,XPosition,IsQuickEntry,AD_Client_ID,ColumnSpan,NumLines,IsAdvancedField,IsDefaultFocus,AD_Column_ID,AD_Tab_ID,EntityType,Created) VALUES (0,'N',0,'N','N',290,'Y',203261,'N','The Cost Adjustment Line indicates the inventory cost adjustment document line (if applicable) for this transaction','Unique line in an Inventory cost adjustment document','Cost Adjustment Line','c8667068-b4f9-43dd-a80d-2b910584a565','Y','N',100,0,100,TO_TIMESTAMP('2014-07-01 15:56:39','YYYY-MM-DD HH24:MI:SS'),'Y','Y',290,1,'N',0,2,1,'N','N',211562,481,'D',TO_TIMESTAMP('2014-07-01 15:56:39','YYYY-MM-DD HH24:MI:SS'))
;
SELECT register_migration_script('201407021018_1003719.sql') FROM dual
;

View File

@ -23,6 +23,7 @@ import java.sql.Timestamp;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_C_DocType;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MAttributeSetInstance;
@ -31,9 +32,13 @@ import org.compiere.model.MInventory;
import org.compiere.model.MInventoryLine;
import org.compiere.model.MProduct;
import org.compiere.model.MProductCategoryAcct;
import org.compiere.model.PO;
import org.compiere.model.X_I_Inventory;
import org.compiere.util.AdempiereUserError;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.compiere.util.ValueNamePair;
@ -73,7 +78,9 @@ public class ImportInventory extends SvrProcess
private int p_AD_OrgTrx_ID = 0;
/** Document Action */
private String m_docAction = null;
private MInventory costingDoc = null;
private int p_C_DocType_ID = 0;
/**
* Prepare - e.g., get Parameters.
*/
@ -107,8 +114,10 @@ public class ImportInventory extends SvrProcess
p_AD_OrgTrx_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("DocAction"))
m_docAction = (String)para[i].getParameter();
else if (name.equals("C_DocType_ID"))
p_C_DocType_ID = ((BigDecimal)para[i].getParameter()).intValue();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
log.log(Level.WARNING, "Unknown Parameter: " + name);
}
} // prepare
@ -135,6 +144,9 @@ public class ImportInventory extends SvrProcess
}
if (p_AD_OrgTrx_ID < 0 ) {
throw new IllegalArgumentException("AD_OrgTrx required!");
}
if (p_C_DocType_ID <= 0 ) {
throw new IllegalArgumentException("Cost Adjustment Document Type required!");
}
acctSchema = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID, get_TrxName());
}
@ -426,28 +438,7 @@ public class ImportInventory extends SvrProcess
noInsertLine++;
//@Trifon update Product cost record if Update costing is enabled
if (p_UpdateCosting) {
String costingLevel = null;
if(product.getM_Product_Category_ID() > 0){
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), product.getM_Product_Category_ID(), p_C_AcctSchema_ID, get_TrxName());
costingLevel = pca.getCostingLevel();
if (costingLevel == null) {
costingLevel = acctSchema.getCostingLevel();
}
}
int costOrgID = p_AD_OrgTrx_ID;
int costASI = line.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(costingLevel)){
costOrgID = 0;
costASI = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) {
costASI = 0;
}
MCost cost = MCost.get (MProduct.get(getCtx(), imp.getM_Product_ID()), costASI
, acctSchema, costOrgID, p_M_CostElement_ID, get_TrxName());
cost.setCurrentCostPrice( imp.getCurrentCostPrice() );
cost.saveEx();
updateCosting(imp, product, line);
}
}
} else {
@ -470,6 +461,21 @@ public class ImportInventory extends SvrProcess
inventory.saveEx();
}
}
if (costingDoc != null) {
if (!DocumentEngine.processIt(costingDoc, DocAction.ACTION_Complete))
{
StringBuilder msg = new StringBuilder();
I_C_DocType docType = costingDoc.getC_DocType();
msg.append(Msg.getMsg(getCtx(), "ProcessFailed")).append(": ");
if (Env.isBaseLanguage(getCtx(), I_C_DocType.Table_Name))
msg.append(docType.getName());
else
msg.append(((PO)docType).get_Translation(I_C_DocType.COLUMNNAME_Name));
throw new AdempiereUserError(msg.toString());
}
costingDoc.saveEx();
}
}
catch (Exception e)
{
@ -493,4 +499,48 @@ public class ImportInventory extends SvrProcess
return "";
} // doIt
private void updateCosting(X_I_Inventory imp, MProduct product,
MInventoryLine line) {
String costingLevel = null;
if(product.getM_Product_Category_ID() > 0){
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), product.getM_Product_Category_ID(), p_C_AcctSchema_ID, get_TrxName());
costingLevel = pca.getCostingLevel();
if (costingLevel == null) {
costingLevel = acctSchema.getCostingLevel();
}
}
int costOrgID = p_AD_OrgTrx_ID;
int costASI = line.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(costingLevel)){
costOrgID = 0;
costASI = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) {
costASI = 0;
}
MCost cost = MCost.get (MProduct.get(getCtx(), imp.getM_Product_ID()), costASI
, acctSchema, costOrgID, p_M_CostElement_ID, get_TrxName());
if (costingDoc == null) {
costingDoc = new MInventory(getCtx(), 0, get_TrxName());
costingDoc.setC_DocType_ID(p_C_DocType_ID);
costingDoc.setCostingMethod(cost.getM_CostElement().getCostingMethod());
costingDoc.setDocAction(DocAction.ACTION_Complete);
costingDoc.saveEx();
}
MInventoryLine costingLine = new MInventoryLine(getCtx(), 0, get_TrxName());
costingLine.setM_Inventory_ID(costingDoc.getM_Inventory_ID());
costingLine.setM_Product_ID(cost.getM_Product_ID());
costingLine.setCurrentCostPrice(cost.getCurrentCostPrice());
costingLine.setNewCostPrice(imp.getCurrentCostPrice());
costingLine.setM_Locator_ID(0);
costingLine.saveEx();
imp.setM_CostingLine_ID(costingLine.getM_InventoryLine_ID());
imp.saveEx();
}
} // ImportInventory

View File

@ -247,6 +247,21 @@ public interface I_I_Inventory
*/
public String getLot();
/** Column name M_CostingLine_ID */
public static final String COLUMNNAME_M_CostingLine_ID = "M_CostingLine_ID";
/** Set Cost Adjustment Line.
* Unique line in an Inventory cost adjustment document
*/
public void setM_CostingLine_ID (int M_CostingLine_ID);
/** Get Cost Adjustment Line.
* Unique line in an Inventory cost adjustment document
*/
public int getM_CostingLine_ID();
public org.compiere.model.I_M_InventoryLine getM_CostingLine() throws RuntimeException;
/** Column name M_Inventory_ID */
public static final String COLUMNNAME_M_Inventory_ID = "M_Inventory_ID";

View File

@ -33,7 +33,7 @@ public class X_I_Inventory extends PO implements I_I_Inventory, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20131031L;
private static final long serialVersionUID = 20140701L;
/** Standard Constructor */
public X_I_Inventory (Properties ctx, int I_Inventory_ID, String trxName)
@ -321,6 +321,34 @@ public class X_I_Inventory extends PO implements I_I_Inventory, I_Persistent
return (String)get_Value(COLUMNNAME_Lot);
}
public org.compiere.model.I_M_InventoryLine getM_CostingLine() throws RuntimeException
{
return (org.compiere.model.I_M_InventoryLine)MTable.get(getCtx(), org.compiere.model.I_M_InventoryLine.Table_Name)
.getPO(getM_CostingLine_ID(), get_TrxName()); }
/** Set Cost Adjustment Line.
@param M_CostingLine_ID
Unique line in an Inventory cost adjustment document
*/
public void setM_CostingLine_ID (int M_CostingLine_ID)
{
if (M_CostingLine_ID < 1)
set_Value (COLUMNNAME_M_CostingLine_ID, null);
else
set_Value (COLUMNNAME_M_CostingLine_ID, Integer.valueOf(M_CostingLine_ID));
}
/** Get Cost Adjustment Line.
@return Unique line in an Inventory cost adjustment document
*/
public int getM_CostingLine_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_CostingLine_ID);
if (ii == null)
return 0;
return ii.intValue();
}
public org.compiere.model.I_M_Inventory getM_Inventory() throws RuntimeException
{
return (org.compiere.model.I_M_Inventory)MTable.get(getCtx(), org.compiere.model.I_M_Inventory.Table_Name)