COGS Entry not posted if Invoice total is zero

I just discovered something weird.

If I generate a sales invoice and I give the customer 100% discount, meaning the invoice total is zero, the cost of goods sold entry will not be posted.

In this scenario you expect the sales to be zero, while the cost of goods sold is whatever the inventory valuation is. Unfortunately this is not so, I have to make the invoice total be at least $1 before ERPNext will post the COGS accounting leg.

Is this a bug or am I missing something ?

This instance is on V10.1.22

Regards

Now am totally confused

The stock on hand is accurately reduced in quantity and value, but for the life of me I cannot determine where the second leg is posted to by the system.

Any ideas anyone ?

I just confirmed the same! If this is a bug, it needs to be fixed asap!!!

Issue raised on Github

https://github.com/frappe/erpnext/issues/15459