web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

sales order invoice with deduction of custom discount

(2) ShareShare
ReportReport
Posted on by 111
hi
i want to invoice sales order with deduction of some discount .
For that, i update the invoice jour.invoice amount after udating the salesparmline.lineamount (packing & invoicng)
but i am getting the error and posting is failed
please guide, i am posting here for 2nd time, i am stuck on it over a month.
i have debug all classes related to packing sales totals and invoicng too but still got this error after update invoicing amount 
720 is updated amount after deduction of discount
800 is originial amount 
errrors of transaction are given below

Posting
Sales order: 006110
Voucher INV-10000822
The transactions on voucher INV-10000822 do not balance as per 6/3/2025. (accounting currency: -80.00 - reporting currency: -80.00)
Voucher transactions
Voucher INV-10000822, date 6/3/2025, account 140100--, transaction currency amount 749.92, accounting currency amount 749.92, reporting currency amount 749.92, currency USD, text
Voucher INV-10000822, date 6/3/2025, account 500150----, transaction currency amount -749.92, accounting currency amount -749.92, reporting currency amount -749.92, currency USD, text
Voucher INV-10000822, date 6/3/2025, account 140100--, transaction currency amount -749.92, accounting currency amount -749.92, reporting currency amount -749.92, currency USD, text
Voucher INV-10000822, date 6/3/2025, account 500100----, transaction currency amount 749.92, accounting currency amount 749.92, reporting currency amount 749.92, currency USD, text
Voucher INV-10000822, date 6/3/2025, account 401100----, transaction currency amount -800.00, accounting currency amount -800.00, reporting currency amount -800.00, currency USD, text
Voucher INV-10000822, date 6/3/2025, account 130100--, transaction currency amount 720.00, accounting currency amount 720.00, reporting currency amount 720.00, currency USD, text
Posting has been canceled.
 
Categories:
I have the same question (0)
  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,346 Super User 2025 Season 2 on at
    sales order invoice with deduction of custom discount
    You're getting the “transactions on voucher do not balance” error because you're manually modifying accounting-related amounts (like InvoiceJour.InvoiceAmount) without ensuring that all dependent transactions and ledger entries (especially customer and revenue accounts) are updated accordingly.

    Problem Summary:

    You tried to apply a custom discount by reducing the InvoiceJour.InvoiceAmount to 720.00 from the original 800.00 — but the ledger entries (e.g., revenue and receivable accounts) still reflect the original 800.00 revenue, which causes the voucher to go out of balance by -80.00.

    Correct and Supported Way to Apply Custom Discounts

    To deduct a discount in Sales Order Invoice posting, do not directly update InvoiceJour. Instead, use one of the supported approaches below.

    Solution Option 1: Use a Custom Miscellaneous Charges Line

    This is the recommended and safe method.

    Steps:

    1. Go to Sales Order > Sales Order Lines > Line > Charges.
    2. Add a negative miscellaneous charge (e.g., -80.00) to reduce the total.
      • Ensure it posts to a discount GL account (e.g., 604000 – Discounts Given).
    3. Recalculate totals.
    4. Post the invoice.
    This way:
    • Sales amount is still 800.00
    • Charge reduces it to 720.00
    • All ledger postings are auto-balanced
    • InvoiceJour will reflect 720.00 net

    Solution Option 2: Update LineAmount via SalesParmLine, Not InvoiceJour

    If you still want to manipulate amounts programmatically (not recommended), do it at the line level using SalesParmLine before invoice posting.

    Example:

    x++
    SalesParmLine parmLine;
    select forUpdate parmLine where parmLine.SalesId == '006110' && parmLine.RecId == yourRecId;
     
    parmLine.LineAmount = 720.00;
    parmLine.setInventNow(); // Ensures packing/slip qty recalculation
    parmLine.doUpdate();
    Then let the system post the invoice. Do not touch InvoiceJour.InvoiceAmount directly – it’s calculated automatically from SalesParmLines.

    🛑 What You Must Avoid:

    • Never directly update InvoiceJour.InvoiceAmount – this breaks financial posting logic.
    • Don't bypass SalesFormLetter_Invoice processing.
    • Don't manually try to balance ledger entries unless you're writing a full custom posting routine, which is high risk and error-prone.

    Recommendation:

    Use Option 1 (Misc Charges) unless you have a business rule that strictly requires custom code – it’s robust, safe, and aligns with D365FO posting logic.

    If your business logic requires programmatic application of discounts, share more details (e.g., fixed per customer, conditional rules), and I can guide you through a correct coding extension using PriceDisc, SalesLine, or Charges.
    Let me know if you'd like sample code for adding the negative charge automatically during invoicing.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,257

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 913 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 611 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans