Colour coding for item in sales order

Colour coding is as
Green means item in stock for the selected warehouse.
Red means item not in stock for selected warehouse.

but while creating sales order colour code is red even stock is present

return (doc.stock_qty<=doc.delivered_qty) ? “green” : “orange” }
this is the actual condition for setting green or orange color code. Its not only about current stock.

Thank you for responding