Realized/UnrealizedGainLoss - how to clear accounts when only one org ?

70 views
Skip to first unread message

Nicolas Micoud

unread,
Oct 10, 2019, 4:57:14 AM10/10/19
to iDempiere
Hello,

I've starting to struggle with multi-currencies and Realized/UnrealizedGainLoss stuff.
I'm not an expert, so I may miss something :)

Here's my scenario :
Accounting Schema in USD
1 invoice of 12000 EUR (July) partially paid (10000) on September

If Invoice is made by Org1 and Payment by Org2, the allocation generate this posting :


   

Which seems correct (the realized gain/loss is recorded)


But if Invoice is made by Org1 and Payment by Org1, the allocation generate nothing

Which seems incorrect as the realized gain/loss is not recorded.

Debugging, I found the reason on Doc_AllocationHdr (line 252)

if ((!as.isPostIfClearingEqual()) && acct_unallocated_cash != null && acct_unallocated_cash.equals(acct_receivable) && (!isInterOrg)) {

                   
// if not using clearing accounts, then don't post amtsource
                   
// change the allocationsource to be writeoff + discount
                    allocationSource
= line.getDiscountAmt().add(line.getWriteOffAmt());
}

Is it normal to check if the allocation is an 'inter org' one ? I mean, in any case, there is a gain or a loss, no ?

Or should I avoid to use PostIfClearingEqual to force the generation of those lines ?

Thanks,

Nicolas

Carlos Antonio Ruiz Gomez

unread,
Oct 10, 2019, 10:02:59 AM10/10/19
to idem...@googlegroups.com
Hi Nicolas, I haven't tested, but analyzing the logic I think the problem can be that the payAcct variable is not set.

That sounds like a bug, and maybe simply setting the payAcct will solve it, can you please test?

Regards,

Carlos Ruiz



Am 10.10.19 um 10:57 schrieb Nicolas Micoud:

Nicolas Micoud

unread,
Oct 10, 2019, 11:51:28 AM10/10/19
to iDempiere
Hi Carlos,

I did the following :


if ((!as.isPostIfClearingEqual()) && acct_unallocated_cash != null && acct_unallocated_cash.equals(acct_receivable) && (!isInterOrg)) {
   
// if not using clearing accounts, then don't post amtsource
   
// change the allocationsource to be writeoff + discount
   allocationSource
= line.getDiscountAmt().add(line.getWriteOffAmt());

   payAcct
= getPaymentAcct(as, line.getC_Payment_ID());
} else {

So payAcct is set in my case ; but RGL is still not done

If I only comment line 346 :
//allocationSource = line.getDiscountAmt().add(line.getWriteOffAmt());

then RGL is done.

But I have no idea of the impact of this change :-/

Thanks,

Nicolas

Carlos Antonio Ruiz Gomez

unread,
Oct 10, 2019, 12:47:08 PM10/10/19
to idem...@googlegroups.com
Hi Nicolas, again, not tested, just reading code, I think the change must be in line 440, use allocationSourceForRGL instead of allocationSource.

So, something like:
                p_Error = createRealizedGainLoss (line, as, fact, bpAcct, invoice,  payAcct, payment,
                    allocationSourceForRGL, allocationAccounted);

That matches the purpose of the name of the variable.

WDYT?

Regards,

Carlos Ruiz




Am 10.10.19 um 17:51 schrieb Nicolas Micoud:

Nicolas Micoud

unread,
Oct 11, 2019, 4:05:55 AM10/11/19
to iDempiere
Hello Carlos,

I've done some rapid tests, and I think is ok.
But as I said yesterday, I may miss something on this part as I'm just starting to use it.
I attach a patch ; could you have a look ?
It also contains the "set payAcct" part ; to avoid a NPE on createRealizedGainLoss

Thanks,

Nicolas
Doc_AllocationHdr.patch

Carlos Antonio Ruiz Gomez

unread,
Oct 14, 2019, 11:26:38 AM10/14/19
to idem...@googlegroups.com
xref


Am 11.10.19 um 10:05 schrieb Nicolas Micoud:
Reply all
Reply to author
Forward
0 new messages