GL Distribution is a powerful feature. It can replace some elements of FactLine to another if certain conditions are satisfied. This set of condition is limited by account elements (Org, Account, Activity, Campaign...). There are situations in our accounting when it is necessary to extend the conditions from the primary document or further. __________________
I want to offer a solution that extends the functionality of GL_Distribution. 1. Create column "WhereClause" in table GL_Distribution. 2. Here we can write any SQL-code, which must return TRUE or FALSE. 3. If SQL code return TRUE, then this GL_Distribution is get, else - discarded. 4. In WhereClause we can use special variables indicated by $$, for example $Record_ID$. This special variables will be replaced by the corresponding values from current FactLine. For example $AD_Table_ID$ will by replaced by 318 when Invoice is posting.
We need modify some class: 1) MDistribution - add new methods public static MDistribution[] get public static MDistribution[] get (see attached file)
2) Fact.java in method public boolean distribute() replace calls old method MDistribution[] distributions = MDistribution.get (dLine.getAccount(), m_postingType, m_doc.getC_DocType_ID());
I would suggest to implement that in the iDempiere way using @ like context variables, and then using the Env.parseVariable methods passing the MFactAcct as the PO parameter.
GL Distribution is a powerful feature. It can replace some elements of FactLine to another if certain conditions are satisfied. This set of condition is limited by account elements (Org, Account, Activity, Campaign...).
There are situations in our accounting when it is necessary to extend the conditions from the primary document or further.
__________________
I want to offer a solution that extends the functionality of GL_Distribution.
1. Create column "WhereClause" in table GL_Distribution.
2. Here we can write any SQL-code, which must return TRUE or FALSE.
3. If SQL code return TRUE, then this GL_Distribution is get, else - discarded.
4. In WhereClause we can use special variables indicated by $$, for example $Record_ID$. This special variables will be replaced by the corresponding values from current FactLine. For example $AD_Table_ID$ will by replaced by 318 when Invoice is posting.
We need modify some class:
1) MDistribution - add new methods
public static MDistribution[] get
public static MDistribution[] get
(see attached file)
2) Fact.java in method public boolean distribute() replace calls old method
MDistribution[] distributions = MDistribution.get (dLine.getAccount(),
m_postingType, m_doc.getC_DocType_ID());
for
MDistribution[] distributions = MDistribution.get (dLine.getAccount(),
m_postingType, m_doc.getC_DocType_ID(), dLine);
and replace old method
distributions = MDistribution.get (dLine.getCtx(), dLine.getC_AcctSchema_ID(),
m_postingType, m_doc.getC_DocType_ID(),
dLine.getAD_Org_ID(), dLine.getAccount_ID(),
dLine.getM_Product_ID(), dLine.getC_BPartner_ID(), dLine.getC_Project_ID(),
dLine.getC_Campaign_ID(), dLine.getC_Activity_ID(), dLine.getAD_OrgTrx_ID(),
dLine.getC_SalesRegion_ID(), dLine.getC_LocTo_ID(), dLine.getC_LocFrom_ID(),
dLine.getUser1_ID(), dLine.getUser2_ID());
for
distributions = MDistribution.get (dLine.getCtx(), dLine.getC_AcctSchema_ID(),
m_postingType, m_doc.getC_DocType_ID(),
dLine.getAD_Org_ID(), dLine.getAccount_ID(),
dLine.getM_Product_ID(), dLine.getC_BPartner_ID(), dLine.getC_Project_ID(),
dLine.getC_Campaign_ID(), dLine.getC_Activity_ID(), dLine.getAD_OrgTrx_ID(),
dLine.getC_SalesRegion_ID(), dLine.getC_LocTo_ID(), dLine.getC_LocFrom_ID(),
dLine.getUser1_ID(), dLine.getUser2_ID(), dLine);