We are running AX 2012 R3 and we have an issue with project accounting distributions connected to a purchase order line item after following a very specific set of steps:
- Create a purchase order line item with an item id and line amount but no project id and approve and confirm the purchase order
- At this point everything is as expected. There is one accounting distribution record linked to the line and no project accounting distribution
- Request change on purchase order and add a project id to the purchase order line item, at this time the line item amount is blanked. User approves and confirms the purchase order again
- At this point everything is still as expected. There are three accounting distribution records. The original, a reversal of the original, and a new one which has a linked project accounting distribution
- Request change on the purchase order again and add the line amount back to the line item
- At this point, the accounting distribution records look correct but something went wrong with the project accounting distribution process because project accounting distributions are getting created for all of the accounting distributions except for the last one. Somehow project accounting distributions are being created for the original accounting distribution and it's reversal but are not being created for the last accounting distribution which is the one that should have an accounting distribution.
This eventually leads to our users posting vendor invoices which have project ids on the lines but no project transaction being generated.
What I found in the code is the class AccountingDistributionProcessor has a delegate which notifies the classAccDistProcessorProjectExtension whenever an accounting distribution is updated. The AccDistProcessorProjectExtension gets the source document lines that were updated and processes each of them. In my case, just one source document line is involved. The AccDistProcessorProjectExtension loops over all of the accounting distributions that are linked to the source document line and tries to add a related ProjectAccountingDistribution record if needed. I noticed as it loops through the accounting distributions, it can add a related project accounting distribution for a variety of reasons (if there's a reference accounting distribution, a parent accounting distribution, a reversed accounting distribution, and a few other scenarios. I can see that the first accounting distribution record which never had a project linked is getting one created from a reversed distribution. This is happening in \Classes\AccDistProcessorProjectExtension#createFromReversedDistribution
This code looks into a map for any accounting distribution recids that were reversed and if it finds one for this source document line then it generates the project accounting distribution and links it to the accounting distribution that it's processing. Then it removes that key from the map. Because it's been removed from the map, when we get around to processing the last accounting distribution which should get an associated project accounting distribution, nothing is found in this map for the source document line and so no project accounting distribution is created.
What I found is if I simply apply an order by recid descending as the accounting distribution records are processed in the processRegularDistributions method, then the latest accounting distribution is processed first and gets a project accounting distribution as expected and the original one does not. This fix seems to work but I'm wondering if anyone who is more familiar with the process of updating project accounting distributions would be able to weigh in on anything I may be missing. Does this seem like a bug in Microsoft's project accounting distribution processor? I'm anxious to change this low level code. I look over at LCS finds 100s of issues around project accounting distributions but nothing is coming up on this particular method (\Classes\AccDistProcessorProjectExtension\#processRegularDistributions).
Is anyone familiar with this process? Any suggestion on getting it fixed?