'This function tries to find quants for the given domain and move/ops, by trying to first limit
the choice on the quants that match the first item of preferred_domain_list as well. But if the qty requested is not reached
it tries to find the remaining quantity by looping on the preferred_domain_list (tries with the second item and so on).
Make sure the quants aren\'t found twice => all the domains of preferred_domain_list should be orthogonal'

def quants_get_reservation(self, qty, move, pack_operation_id=False, lot_id=False, company_id=False, domain=None, preferred_domain_list=None):

    reservations = [(None, qty)]
    pack_operation = self.env['stock.pack.operation'].browse(pack_operation_id)
    location = (pack_operation.location_id if pack_operation else move.location_id)
    if (location.usage in ['inventory', 'production', 'supplier']):
        return reservations
    restrict_lot_id = (lot_id if pack_operation else (move.restrict_lot_id.id or lot_id))
    removal_strategy = move.get_removal_strategy()
    domain = self._quants_get_reservation_domain(move, pack_operation_id=pack_operation_id, lot_id=lot_id, company_id=company_id, initial_domain=domain)
    if ((not restrict_lot_id) and (not preferred_domain_list)):
        meta_domains = [[]]
    elif (restrict_lot_id and (not preferred_domain_list)):
        meta_domains = [[('lot_id', '=', restrict_lot_id)], [('lot_id', '=', False)]]
    elif (restrict_lot_id and preferred_domain_list):
        lot_list = []
        no_lot_list = []
        for inner_domain in preferred_domain_list:
            lot_list.append((inner_domain + [('lot_id', '=', restrict_lot_id)]))
            no_lot_list.append((inner_domain + [('lot_id', '=', False)]))
        meta_domains = (lot_list + no_lot_list)
    else:
        meta_domains = preferred_domain_list
    res_qty = qty
    while (float_compare(res_qty, 0, precision_rounding=move.product_id.uom_id.rounding) and meta_domains):
        additional_domain = meta_domains.pop(0)
        reservations.pop()
        new_reservations = self._quants_get_reservation(res_qty, move, ops=pack_operation, domain=(domain + additional_domain), removal_strategy=removal_strategy)
        for quant in new_reservations:
            if quant[0]:
                res_qty -= quant[1]
        reservations += new_reservations
    return reservations
