Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDEMPIERE-4892 Auto Period doesn't check only org schema #803

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions org.adempiere.base/src/org/compiere/model/MAcctSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ public static synchronized MAcctSchema[] getClientAcctSchema (Properties ctx, in
s_schema.put(key, Arrays.stream(retValue).map(e -> {return new MAcctSchema(Env.getCtx(), e).markImmutable();}).toArray(MAcctSchema[]::new));
return retValue;
} // getClientAcctSchema

public static MAcctSchema[] getSchemasByOrg(Properties ctx, int AD_Client_ID, int AD_Org_ID, String trxName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have basic javadoc here

{
MAcctSchema[] list=getClientAcctSchema ( ctx, AD_Client_ID, trxName);
ArrayList<MAcctSchema> listByOrg = new ArrayList<MAcctSchema>();

for (MAcctSchema schema: list)
{
if (schema.getAD_OrgOnly_ID()==AD_Org_ID)
listByOrg.add(schema);
}

return listByOrg.toArray(new MAcctSchema[listByOrg.size()]);
}

/** Cache of Client AcctSchema Arrays **/
private static CCache<Integer,MAcctSchema[]> s_schema = new CCache<Integer,MAcctSchema[]>(I_AD_ClientInfo.Table_Name, I_AD_ClientInfo.Table_Name+"|MAcctSchema[]", 3, 120, false); // 3 clients
Expand Down
14 changes: 13 additions & 1 deletion org.adempiere.base/src/org/compiere/model/MPeriod.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,19 @@ public boolean isOpen (String DocBaseType, Timestamp dateAcct)
return false;
}

MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
MAcctSchema as = null;
MAcctSchema[] asList = MAcctSchema.getSchemasByOrg(getCtx(), getAD_Client_ID(), getAD_Org_ID(), get_TrxName());
if(asList != null && asList.length > 0) {
for(MAcctSchema schema:asList) {
as = schema;
if(schema.isAutoPeriodControl())
break;
}
}

if(as == null)
as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();

if (as != null && as.isAutoPeriodControl())
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @igorpojzl ,

The current model is actually very open ended. For e.g, with 2 org, you can have:

  1. 2 acctschema with orgonly_id for each org.
  2. 2 acctschema with a tenant schema for all and an org level schema with orgonly_id for second org.
  3. 3 acctschema with 1 schema for org1 and 2 schema for org2.

I guess to be complete, you should check client level schema and all org level schema with orgonly_id = ad_org_id.

Timestamp today = TimeUtil.trunc(new Timestamp (System.currentTimeMillis()), TimeUtil.TRUNC_DAY);
Expand Down