Voucher creation at the time of sales order posting

Hi Everyone,

I am working in D365FO. There is a requirement to apply additional allowance to the Sales order invoice amount. And for that allowance amount , a voucher entry should be created while posting the Sales order invoice.

Found out the class “SalesInvoiceJournalPost” is used to create voucher transactions.

But not sure how to add an entry to the method “postCustVend”.

Could anyone please help.



What exactly do you mean by “additional allowance”? Maybe the standard feature of charges would meet your requirements without any coding.

Hi Martin,

Thanks for your reply. This is additional allowance given to the customer. If the invoice amount is 500 , allowance given to him is 200. So a voucher entry needs to be created for that 200. Whether this can be handled using charges?

Can you explain the logic, please? It’s not clear how the system should decide that the charge should be added and that it should be 200 (in some currency).

It is similar like discount. But this allowance should be applied only at the time of invoice and not in in SO line level. I have created a separate setup form for this where I will mention the customer acc, discount % and ledger account. System should check this setup form while posting the SO invoice

Oh, so you want a discount and not a charge?

Then are you sure you need to apply the discount at invoice level and not for a sales order? Discounts for whole orders (not individual lines) are already supported out of the box for many years. But note that an order and an invoice are different things; a single order can be invoiced partially in several invoices and one invoices can contain several orders.

Yes. This is at invoice level. Also it is going to be a single order and no partial invoice.

If there always is a single invoice for each order, then applying the discount for an order is the same as applying it for an invoice. Therefore the standard feature should work for you.

Look at the discussion in How to apply Total Discount?, for instance.