Deduct already-reversed prepayment GST on AU sales prepayment credit memos - #9807
Open
Franco111000 wants to merge 1 commit into
Open
Deduct already-reversed prepayment GST on AU sales prepayment credit memos#9807Franco111000 wants to merge 1 commit into
Franco111000 wants to merge 1 commit into
Conversation
The APAC layer tracks how much prepayment GST a final invoice has already deducted so that a later prepayment credit memo only reverses the remainder. The purchase side has both halves of that mechanism, but on sales the buffer filled by SavePrepmtVATDeducted was never drained, so Sales Line fields 28006 and 28007 stayed at zero and a prepayment credit memo posted after a partial final invoice reversed the full prepayment GST again. This ports the missing DividePrepmtVATDeducted and DistributeAmount from Purch.-Post and calls DividePrepmtVATDeducted from PostUpdateOrderLine, mirroring the purchase call site. Three deliberate deviations from a verbatim port: - SavePrepmtVATDeducted now stores the deducted GST with the same positive sign convention the purchase saver uses, because both credit memo read sites subtract these fields. The stored values were previously unread on sales, so the sign change is inert outside the new path. - DeductedVATBaseAmount in Sales-Post Prepayments UpdateVATOnLines is reset per line. It was only ever assigned on the Full GST credit memo path and never cleared between iterations, which was harmless while the source field was always zero but would have leaked one line's deducted base into the next once the fields are populated. - The credit memo branch of UpdateSalesDocument clears both fields alongside the existing prepayment resets, so a re-invoiced prepayment starts a clean deduction cycle. The line number buffer is also reset before deletion in the ported procedure, since the purchase original deletes it while a filter from the last iteration is still active. Adds a regression test covering prepayment invoice, partial final invoice, then prepayment credit memo under Full GST on Prepayment, asserting the deducted fields on the order line and the reduced GST on the credit memo.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
AU only: a sales prepayment credit memo posted after a partial final invoice reverses the full prepayment GST instead of only the part that has not been deducted yet, so the customer ledger entry and the G/L entries carry too much GST when the order is re-invoiced.
The APAC layer already has a mechanism for exactly this: during final invoice posting,
SavePrepmtVATDeductedcollects the GST reversed by the prepayment deduction lines into a buffer, and the credit memo read sites subtract Sales Line fields 28006Prepmt. VAT Amount Deductedand 28007Prepmt. VAT Base Deductedfrom the prepaid GST (SalesPostPrepayments1200-1201 and 1250-1251, gated by Full GST on Prepayment plus the credit memo document type). On the purchase side the mechanism is complete:Purch.-Postdrains its buffer onto the purchase lines throughDividePrepmtVATDeductedandDistributeAmount(7488-7545, called at 8428). On the sales side only the first half exists: the buffer is filled (SalesPost7769, called 1156) and nothing ever drains it, so both fields stay at zero for the life of every document and the subtraction never subtracts anything.This PR completes the sales side by porting
DividePrepmtVATDeductedandDistributeAmountfromPurch.-Postand calling the former fromPostUpdateOrderLine, mirroring the purchase call site. Three deliberate deviations from a verbatim port, each needed for the port to be correct:SavePrepmtVATDeducted. The prepayment deduction lines are built with Quantity = -1 on both sides, so their amounts are negative. The purchase saver negates them into positive values (PurchPost7493-7494); the sales saver did not. Both credit memo read sites subtract the fields, so the stored values must be positive. The sales saver now negates exactly like the purchase one. This edit is inert for existing behaviour: the two buffer fields it feeds had no reader on the sales side until this PR.DeductedVATBaseAmountinUpdateVATOnLines. The variable is procedure-scoped, assigned only on the Full GST credit memo path, and consumed on every Full GST line. While field 28007 was always zero this was harmless; with the field populated, one line's deducted base would leak into the next line in the same run. Reset to zero at the top of each iteration.UpdateSalesDocumentalready rebasesPrepmt. Amt. Incl. VATandPrepayment Amountand clears the other per-cycle prepayment fields (2000-2004). Both deducted fields are cleared there too, so a prepayment that is re-invoiced after a credit memo starts a clean deduction cycle instead of subtracting the previous cycle's deduction again. The purchase side does not do this and keeps document-lifetime accumulators; aligning purchase the same way may be worth a follow-up, but changing purchase behaviour is out of scope here.One more small deviation: the ported procedure resets the line number buffer before deleting it. The purchase original deletes that buffer while the filter from the last loop iteration is still active, which only clears the last group.
Out of scope: the fix proposed in the issue description (extending
RestorePrepmtAmountswithPrepmt. VAT Base Amt.) is not part of this change. That procedure saves and restores a field thatUpdateVATOnLinesdeliberately rewrites per posting, and under Full GST the rewrite keeps the field unchanged from the second prepayment onward, so an unconditional restore would double it. The root cause analysis is on the issue.Linked work
Fixes #8896
Area label: the issue carries Finance. I do not have label permissions, so a maintainer would need to set it.
How I validated
SalesPost1156/7769 vsPurchPost1210/7488), drain (PurchPost7510/8428, sales previously absent), read sites (SalesPostPrepayments1200/1250,PurchasePostPrepayments866/916), and the temp-to-database flush (ModifyTempLine, wholesaleTransferFields, so the drained values persist).Currencyused byDistributeAmountis initialised beforePostUpdateOrderLineruns (GetCurrencyat 346,FinalizePostingat 372), matching the purchase flow.GSTOnSalesPrepmtCrMemoAfterPartialFinalInvoiceinERM GST On Prepayments II): prepayment invoice, paid, partial final invoice, then prepayment credit memo under Full GST on Prepayment. It asserts the deducted GST amount and base on the order line against the posted deduction lines, and that the credit memo GST equals the prepaid GST minus the deducted GST. The existing suite cannot catch this defect: every current Full GST credit memo test posts the credit memo before any final invoice, so the fields are still zero at the read sites either way.Risk & compatibility
IsFullGSTplus the credit memo document type, and nothing else reads these fields.Editable = falseand appear on no page, report, or API in the repository.