Incorrect project cost and margin when using payment term discounts

So ERPNext generally does not consider discounts a cost to a project - how can I change this?

I have these payment terms on an invoice. As you can see, there is a discount.

Here is what the cost and margin project info looks like:

The invoice amount and purchase cost are both correct, but the margin is clearly incorrect. The discount received is not being calculated as a cost so the margin isn’t calculating correctly. I double checked and the project is attached to the GL entry so it seems that this behavior is on purpose.

The only way around this that I found was to discount the entire invoice upon creation by using the “additional discount” fields… but that doesn’t work for my situation.

Is there any way to change how this is calculated?