Get unit from sql query
The margin per product is under performing because it has to make a new query to get the unit in get_quantity
which trigger a new read. The problem is that the table query can be slow on large database.
So it will be better to add join to product template and retrieve the default uom.