null-check for case when the aggregate function is ran on an empty result set (https://github.com/Starcounter/Starcounter/issues/2111)
fix saving a new invoice