Hey guys,
I have a slightly lengthy project I've been tasked with, so I'll spare you the details, unless somebody is familiar with the factory coding and what everything does.
But essentially, I created a custom field on the "Sales Invoice Line" table and need to write to it. I'm trying to piggyback off of a process that happens at some stage during the posting of a sales order (which creates a sales invoice).
The most relevant thing I was able to find, after a lot of poking around in C/AL code, is codeunit 20. I tried entering some debug messages, simple things like "MESSAGE('NameOfFunction');" at the top of each function, and surely enough when I would post a test invoice it would pop up the message boxes. But as I checked the records during the process, it looks like there are other codeunits running besides just that one.
To avoid having to go deeper and deeper down the rabbit hole, I'm curious if there's some sort of a "debug mode" where I can see what codeunits it's running and at what part. Basically a "trace" mode where I can manually step it through its paces until the data I'm looking for is written.
Or if anybody here is proficient with the factory-written codeunits (as well as the C/AL code built into the RTC pages that calls said codeunits), I can explain what I'm trying to do. I just figured it would be better do to my own debugging to save others the effort.
0
Answers
Alternatively, does anyone know what codeunit actually posts transactions to the general ledger? (Table 17, G/L Entry)
It's not codeunit 20, I don't think - but it's called from there.
Not sure where you got codeunit 20 (typo perhaps?).
Sales documents are posted via Codeunit 80 and this calls Codeunit 12 to post to G/L Entry
Correct, I meant codeunit 80 and must have remembered wrong. The one called Sales-Post (80)
Codeunit 12 might be what I want then.
Basically what I need to do is to post the "actual cost" of an order to the invoice... currently, the "unit cost" field is just copied from the order, and not re-calculated based on FIFO/replenishment policy settings. So if you have a part with an incorrectly typed cost, it posts to the invoice incorrectly. Which is a nightmare for reporting.
I created a new field in Sales Invoice Line called "actual cost" and basically just need to populate that when an invoice is posted. But after two days of chasing the rabbit down the rabbit hole I can't figure it out.
What trips me up is that there are two different functions, and they seem to operate at different times. One codeunit only gets called when you view an invoice (it's not stored anywhere).
Under a posted sales invoice (in RTC), if you click Statistics there's an "Adjusted Cost ($)" field, which shows the actual calculated cost of that order based on FIFO or whatever other policy the line item uses.
The C/AL code for that page (397, Sales Invoice Statistics) calls a codeunit called Cost Calculation Management which seems to do the calculation - however, that function requires an already-posted sales invoice line. So I don't think I can use it DURING the posting process....
At the same time, two G/L entries get posted when you create an invoice, and that posts the adjusted amount as well - though not as user-friendly (if the order cost says $50 and the actual cost is $100, it'll just post $50 and you would have to do the math to get $100 as actual cost)
Seems like such a simple thing to ask for, and I'm honestly surprised this isn't built in, but I've spent 3 days poking around trying to chase after code with no success. Maybe you'd know better than I do, Kishorm?
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Yes in regards to FIFO costing. And I have no idea about purchase receipts, I'm just the IT guy.
But I think that's the issue right there.
Our sales guys will make a sales order before we get a purchase receipt, so the cost is $0. We don't create the sales INVOICE until after we get a purchase invoice, but the ORDER has been made already. And it seems like what NAV does is just copies that "unit cost" right from the order to the invoice without recalculating it - and that's what I need to change.