No sure if it is correct but in works in my case. I fixed it in control.lua
function put(surface,inv,item,amount)
if not global.pool[surface.name] then global.pool[surface.name] = {} end
if not global.pool[surface.name][item] then
global.pool[surface.name][item] = {amount=0, category='main'}
end
if inv.get_insertable_count(item) < amount then return end
local content = inv.get_contents()
local needed = amount
if content[item] then needed = needed - content[item] end
if needed <= 0 then return end
local amount_left = global.pool[surface.name][item]['amount']
if amount_left == 0 then return end
if amount_left < needed then needed = amount_left end
global.pool[surface.name][item]['amount'] = global.pool[surface.name][item]['amount'] - needed
inv.insert({name=item, count=needed})
end
Logic is following: we get amount that left in quantum storage and if it is 0 then we exit. Next we check if amount left is grater or equal to requested. If it is not, we insert leftovers insted of requested amount