When setting the product quantities, force a small difference in the creation time.
This is important because Odoo then sorts the quantities by in_date, and when they all have the same time, sorting is a bit left to chance, and random integration errors are introduces
This is also closer to a real flow, as we woulnd't create 2 quantities at the same time.
A recordset object is not reliable enough to use as a key for the
built-in 'sorted' and 'itertools.groupby' functions (sometimes it works,
sometimes not).
Using the ID of the record (here the product ID) can fix the problem, but the
'group_lines()' has been totally rewritten for a simpler implementation without
any use of 'sorted' or 'itertools.groupby' functions to group the wizard lines
by product: an iteration on lines to fill a dictionary does the job.