Use grouped_slice on locations when computing quantity

As location_ids is used by a IN clause in products_by_location, the caller must
be careful about the length of this list.

issue3977
review11411002